簡體   English   中英

C#WinForm ClickOnce應用程序在安裝后無法正常工作

[英]C# WinForm ClickOnce application doesn't work after installation

我構建的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;
                }
            }
        }
    }
}

我想到了! 問題既不是登錄形式也不是主要形式,而是實體框架在構造函數上引發異常。

我只是關注博客文章條目並添加:

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

到構造函數。 現在,它就像魅力一樣運作!

謝謝大家的回應

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM