Jader Dias Jader Dias - 3 months ago 7
C# Question

How to prevent a WPF app from loading?

I want that the WPF application starts only in certain conditions. I tried the following with no success:

public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
if (ConditionIsMet) // pseudo-code
{
base.OnStartup(e);
}
}
}


But the app runs normally even when the condition is not met

Answer

Try this:

protected override void OnStartup(StartupEventArgs e)
{
    base.OnStartup(e);
    if (MyCondition)
    {
        ShowSomeDialog("Hey, I Can't start because...");
        this.Shutdown();
    }
}
Comments