PureMVC Architects Lounge

PureMVC Manifold => Standard Version => Topic started by: JCabot on January 16, 2008, 09:53:20



Title: Startup idiom
Post by: JCabot on January 16, 2008, 09:53:20
What's the recommended way of performing startup in a windows application? The way I have been playing around with it, I have the following classes:

:
    class ApplicationRunner
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [MTAThread]
        static void Main()
        {
            IFacade facade = ApplicationFacade.getInstance();
            facade.startup(new Form1());
        }
    }

    class ApplicationFacade : Facade, IFacade
    {
        ...
        public override void startup(object app)
        {
            notifyObservers(ApplicationFacade.APP_STARTUP, app);
            Application.Run(app as Form);
        }
    }

just wondered what other peoples opinions are? Is there really a need to have an ApplicationRunner class? or just put the main method in the ApplicationFacade? Where do you recommend putting Application.Run (the built in .NET thing) in the facade or startup command? What are the Java guys doing?

[Edit: oops forgot some parts]


Title: Re: Startup idiom
Post by: puremvc on January 16, 2008, 08:23:28
Jason,

You might want to post this question to the Port Authority (with less C# and more generically stated) so the Java guys will see it.

-=Cliff>


Title: Re: Startup idiom
Post by: adamczak on February 03, 2009, 01:06:17
I wanted to post a startup idiom for WPF applications.  There is a timing issue on when the main window is available for the application facade startup.  The way I found that works great is to override your OnStartup event of you application in your App.xaml.cs file (this is the default file name generated by Visual Studio), and instantiate your main window by hand.  This is the suggested method of doing things if you need access to your main window in the startup event.  So first, you have to remove the StartupUri attribute from your App.xaml source.  Then you override your OnStartup event so it looks something like this:

:
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
MainWindow window = new MainWindow();
ApplicationFacade facade = (ApplicationFacade) ApplicationFacade.Instance;
facade.Startup(window);
window.Show();
}