0

I have a small app(C# WPF) that starts automatically with system, but i want that main window of my program will not shown when it starts from autorun(with command-line parameter autorun).

I written this code:

    protected override void OnStartup(StartupEventArgs e)
    {

        if (e.Args.Length == 0) 
            this.Run(new MainWindow());

        base.OnStartup(e);

    }

But it didn't work... So how i can check existence of my autorun parameter from App.xaml.cs and prevent opening MainWindow?

Thanks.

2
  • Have you tried to attach a debugger and see why the window opens? Commented May 1, 2013 at 5:53
  • Window opens by dispatcher, and when i try to override event OnStartup i get exception: InvalidOperationException Commented May 1, 2013 at 6:13

1 Answer 1

2

Find StartupUri attribute at the top of your App.xaml file and remove it:

override the OnStartup as below

protected override void OnStartup(StartupEventArgs e)
{
    base.OnStartup(e);

    if (e.Args.Length == 0)
    {
        // no argument 
        // do stuff 
    }
    else
    {
        // with arguments
        // do stuff 
    }
    this.Shutdown();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.