The link to the original of this useful article is below, for anyone who wishes to follow any of it's links:
http://blogs.msdn.com/b/jfoscoding/archive/2005/08/24/455579.aspx Chip ________________________________ From: BT [mailto:[email protected]] Sent: Saturday, April 14, 2012 12:41 PM To: [email protected] Subject: Re: .net Script Run() VS run( ApplicationContext ) question Hi Rick, Read this and I think you get the idea. Bruce MSDN Blogs > jfo's coding > Starting an application without showing a form Starting an application without showing a form 4232/ProfileUrlRedirect.ashx jfoscoding 24 Aug 2005 10:23 AM 3 There were a lot of good comments/questions about keeping your UI responsive, if you're interested in threading/application contexts etc, it's worth a peek . I thought I'd rehash something today I've already talked about, but it is buried in my how to build notify icon (system tray) applications article , and I think it's worthy of it's own coverage here: how to run an application without showing a form Dissecting Application.Run If you have created a Windows Forms application, you may have happened across this line in Main: Application.Run(new Form1()); Magically, after calling this, the Form appears and events start firing left and right. Here's what is actually happening, not quite so magically: //Taking a microscope to Application.Run - //create the form, and call initialize component Form1 form1 = new Form1(); // create an application context ApplicationContext applicationContext = new ApplicationContext(); // Set applicationContext.MainForm so that // when form1 closes, exit the application context applicationContext.MainForm = form1; // Call Application.Run which will // - call applicationContext.MainForm.Show() // - begin processing events Application.Run(applicationContext); From this code, we can intuit that the ApplicationContext defines when the Application should exit. In fact the point of all the overloads to Application.Run is to help the Application know when to quit. Running an application without showing a form There are really two options here: Instead of calling Application.Run with an argument, call Application.Run() to start processing messages with NO arguments, then Application.Exit() when finished. This is not very elegant as a missed call to Application.Exit means your application will keep running even though there is no UI present. A much cleaner solution is to inherit from the application context class and redefine when you think the application should quit. The second solution is covered in depth with sample here . Windows Forms Share on Facebook Share on Twitter Share on Digg Share on del.icio.us More Comments Loading... C 2012 Microsoft Corporation. Terms of Use Trademarks Privacy Statement Report Abuse 5.6.402.223 ----- Original Message ----- From: RicksPlace <mailto:[email protected]> To: [email protected] Sent: Saturday, April 14, 2012 9:22 AM Subject: .net Script Run() VS run( ApplicationContext ) question Hi Aaron et al. Is there any advantage of starting a Vb.net Script using Run( ApplicationContext) versus Run() method? I have tested them and They both work but I am wondering about if either would be more robust when taking the fact that WindowEyes, a ThirdParty Application like VWD and the vb.net script are running at the same time. I have not found any articles yet on if running in a new ApplicationContext class would help or hinder cross messaging, thread priorities and, or, all that other Systems Programmer heavy weight stuff. As far as I can tell it just specifies another class to use in place of a form and watches for exiting of that class in this case. Does that sound right? Any comments or suggestions?
