If you have a Winforms application that auto loads data, there is no doubt that you’ll have come across the problem of data loading at design time (i.e. when opening the code in the designer). At best, this slows the designer down, at worst it might crash VS and prevent the control from rendering. Typically, I have used this as a test:
if (System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")
This tests to see if the code is being executed under the account Visual Studio uses. This has the potential to be flaky for various reasons, I have discovered a better way to achieve what I originally wanted:
if(System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime)