In this Winform app, I have some forms loading SQL methods. They execute that code as expected at runtime, every time they are loaded.
But why do they execute the load method every time I open them in Visual Studio?
I'm using Visual Studio 2015 CE
In this Winform app, I have some forms loading SQL methods. They execute that code as expected at runtime, every time they are loaded.
But why do they execute the load method every time I open them in Visual Studio?
I'm using Visual Studio 2015 CE
Because VS designer executes constructors of forms to display it in design time.
To prevent it, you can use this code to check DesignMode property:
if (!DesignMode)
{
//... run sql
}
More complicated with LicenseManager:
if (LicenseManager.UsageMode != LicenseUsageMode.Designtime)
{
//... run sql
}