安装后,C#WinForm ClickOnce应用程序无法运行

时间:2014-08-26 18:34:07

标签: c# .net winforms entity-framework clickonce

我构建的ClickOnce应用程序已成功安装并显示应用程序的登录屏幕。但是,当我提交有效的登录信息时,它不会转到主表单或任何地方。是不是这个代码禁止它通过?目标框架是.Net 4.5,实体框架6是数据库层。

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
    bool mutexCreated = true;
    using (Mutex mutex = new Mutex(true, Application.ProductName, out mutexCreated))
    {
        if (mutexCreated)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            frmLogin loging = new frmLogin();
            Application.Run(loging);

            if (!loging.UserID.Equals(""))
            {
                Application.Run(new frmMainScreen() { UserID = loging.UserID});
            }
        }
        else
        {
            Process current = Process.GetCurrentProcess();
            foreach (Process process in Process.GetProcessesByName(current.ProcessName))
            {
                if (process.Id != current.Id)
                {
                    MessageBox.Show("Another instance of " + Application.ProductName + " is already running.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);

                    break;
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我明白了!问题既不是登录也不是主要形式,而是实体框架在构造函数上抛出异常。

我刚刚关注了this博客文章,并添加了:

var type = typeof(System.Data.Entity.SqlServer.SqlProviderServices); 

到构造函数。现在,它的工作就像一个魅力!

感谢大家的回复

相关问题