.NET Windows Forms design time rules

后端 未结 5 1104
我在风中等你
我在风中等你 2020-12-30 08:53

I have an object that starts a thread, opens a file, and waits for input from other classes. As it receives input, it writes it to disk. Basically, it\'s a thread safe data

5条回答
  •  执念已碎
    2020-12-30 09:17

    You could also use this to check if the Visual Studio Designer is running the code:

    public static bool DesignMode
    {
        get {  return (System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv"); }
    }
    

    Then in Form_Load:

    if (!DesignMode)
    {
        // Run code that breaks in Visual Studio Designer (like trying to get a DB connection)
    }
    

    However, this is less elegant than using the LicensManager.UsageMode, but it works (until Microsoft changes the name of the process Visual Studio runs under).

提交回复
热议问题