<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Keeping your UI Responsive and the Dangers of Application.DoEvents</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx</link><description>What’s the difference between Application.Run and Application.DoEvents? Application.Run continually processes window messages for your application, raising events as necessary. Application.DoEvents processes all the window messages in the queue until</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Keeping your UI Responsive and the Dangers of Application.DoEvents</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#448580</link><pubDate>Sun, 07 Aug 2005 01:05:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:448580</guid><dc:creator>zzz</dc:creator><description>Too bad the DoEvents docs doesn't mention anything like: This method is mostly used for workaround purposes. Use method/pattern X instead.&lt;br&gt;&lt;br&gt;There is a sample that suggests example use of &amp;quot;Call Application.DoEvents to force a repaint&amp;quot;. I guess that's workaround when you need to &amp;quot;force&amp;quot;. Isn't having such samples suggest that DoEvents is the correct way of doing x instead of being a workaround.&lt;br&gt;&lt;br&gt;It would be good if such workaround methods had a clear note like this blog entry that if you need to use it you may have a bad design or whatever.&lt;br&gt;&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsApplicationClassDoEventsTopic.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsApplicationClassDoEventsTopic.asp&lt;/a&gt;</description></item><item><title>Blog link of the week 31</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#448809</link><pubDate>Mon, 08 Aug 2005 01:58:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:448809</guid><dc:creator>Daniel Moth</dc:creator><description>Blog link of the week 31</description></item><item><title>Any threading-related issues with Application.Run()?</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#448895</link><pubDate>Mon, 08 Aug 2005 10:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:448895</guid><dc:creator>Vladimir Klisic</dc:creator><description>If I need to create a window (not necessarily a Form, could be a NativeWindow) in a separate thread, it would need to run its own message loop -- something like the old PeekMessage/TranslateMessage/DispatchMessage loop.&lt;br&gt;&lt;br&gt;Looks like calling Application.Run() from that thread is the way to do that, but are there any special considerations when calling Application.Run() from another thread (other that the main one that already called it)? &lt;br&gt;&lt;br&gt;Would it be a good idea to do it at all?&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Keeping your UI Responsive and the Dangers of Application.DoEvents</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#449639</link><pubDate>Wed, 10 Aug 2005 00:53:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:449639</guid><dc:creator>Jankrod</dc:creator><description>So Maybe you can help me. My current use for a possible DoEvent is to keep the application resizable, movable, and minimize-able when doing heavy processing. DoEvents can do this for me, but I don't want any of the elements on the screen to be active. With the DoEvent you can minimize, but you can also click on other things and that mess up stuff when I'm trying to do calculations.&lt;br&gt;&lt;br&gt;What I really want is a DoMinimizeAndMaximizeEvent, so some way to call the events directly, but not all of them. I can check with GetQueueStatus, if one of those are in the queue but I cant restrict the other event from going into the queue.</description></item><item><title>Getting away from Application.DoEvents</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#451547</link><pubDate>Sun, 14 Aug 2005 19:32:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:451547</guid><dc:creator>sano the super geek</dc:creator><description>Another great blog entry by Jessica Fosler: Keeping your UI Responsive and the Dangers of Application.DoEvents...</description></item><item><title>re: Keeping your UI Responsive and the Dangers of Application.DoEvents</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#451567</link><pubDate>Sun, 14 Aug 2005 20:45:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:451567</guid><dc:creator>ShadowChaser</dc:creator><description>I agree completely about Application.DoEvents. Don't forget that it also adds objects to the garbage collector each time it is run, creating memory &amp;amp; performance issues when placed in a tight loop.&lt;br&gt;&lt;br&gt;That said, developers are really backed against a wall when developing WinForms apps that need code to &amp;quot;hook&amp;quot; into the main application loop, like games. There are no easy solutions outside of nasty hacks or building from the ground up using Interop</description></item><item><title>re: Keeping your UI Responsive and the Dangers of Application.DoEvents</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#451791</link><pubDate>Mon, 15 Aug 2005 19:17:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:451791</guid><dc:creator>jfoscoding</dc:creator><description>zzz - you have a great point RE the docs, I'll file a bug against the documentation.  You're also welcome to file a bug using product feedback:&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://lab.msdn.microsoft.com/productfeedback/"&gt;http://lab.msdn.microsoft.com/productfeedback/&lt;/a&gt;</description></item><item><title>re: Keeping your UI Responsive and the Dangers of Application.DoEvents</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#451799</link><pubDate>Mon, 15 Aug 2005 19:33:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:451799</guid><dc:creator>jfoscoding</dc:creator><description>Vladimir:&lt;br&gt;I assume you're thinking about doing some message passing or something?&lt;br&gt;&lt;br&gt;Running the message loop on the second thread in and of itself wont be a problem, I think stopping it will. If you dont stop the message loop on the second thread, the program wont exit:&lt;br&gt;&lt;br&gt;Try runnning this under the debugger&lt;br&gt;&lt;br&gt;            Thread t = new Thread(new ThreadStart(NewThread));&lt;br&gt;            t.Start();&lt;br&gt;		}&lt;br&gt;&lt;br&gt;        [STAThread]&lt;br&gt;        private void NewThread() {&lt;br&gt;            Application.Run();&lt;br&gt;        }&lt;br&gt;&lt;br&gt;If you dont kill the message pump on the second thread, you'll notice in the debugger that while the form closes, the application doesnt exit.&lt;br&gt;&lt;br&gt;&lt;br&gt;One way you could manage the lifetime of the message pump on the second thread is to use an ApplicationContext:&lt;br&gt;&lt;br&gt;   [STAThread]&lt;br&gt;        private void NewThread() {&lt;br&gt;            Application.Run(new BackgroundThreadApplicationContext(this));&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        public class BackgroundThreadApplicationContext : ApplicationContext {&lt;br&gt;            public BackgroundThreadApplicationContext(Form mainForm) {&lt;br&gt;                if (mainForm != null) {&lt;br&gt;                    mainForm.Closing +=new CancelEventHandler(mainForm_Closing);&lt;br&gt;                }&lt;br&gt;            }&lt;br&gt;&lt;br&gt;            private void mainForm_Closing(object sender, CancelEventArgs e) {&lt;br&gt;                Form mainForm = sender as Form;&lt;br&gt;                if (mainForm != null) {&lt;br&gt;                    mainForm.Closing -=new CancelEventHandler(mainForm_Closing);&lt;br&gt;                }&lt;br&gt;                this.ExitThread();&lt;br&gt;            }&lt;br&gt;        }&lt;br&gt;&lt;br&gt;More details of how to use ApplicationContext are up at &lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://www.windowsforms.net/articles/notifyiconapplications.aspx"&gt;http://www.windowsforms.net/articles/notifyiconapplications.aspx&lt;/a&gt;&lt;br&gt;</description></item><item><title>re: Keeping your UI Responsive and the Dangers of Application.DoEvents</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#451803</link><pubDate>Mon, 15 Aug 2005 19:40:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:451803</guid><dc:creator>jfoscoding</dc:creator><description>Jankrod - &lt;br&gt;I dont know if it's possible, but I'd try moving the &amp;quot;heavy processing&amp;quot; to a background thread and update your UI in chunks.  You may also want to Thread.Sleep the &amp;quot;heavy processing&amp;quot; thread to yield some time back to your UI thread so that it has the opportunity to be a little more responsive to users.&lt;br&gt;&lt;br&gt;In Whidbey the BackgroundWorker API helps make this easy, but it's just a fluffy layer on what was already out there in 1.0/1.1 - just use Invoke and/or BeginInvoke to communicate back with the main UI.  &lt;br&gt;&lt;br&gt;An example is here&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/jfoscoding/archive/2005/05/26/422405.aspx"&gt;http://blogs.msdn.com/jfoscoding/archive/2005/05/26/422405.aspx&lt;/a&gt;</description></item><item><title>re: Keeping your UI Responsive and the Dangers of Application.DoEvents</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#451807</link><pubDate>Mon, 15 Aug 2005 19:44:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:451807</guid><dc:creator>jfoscoding</dc:creator><description>ShadowChaser: &lt;br&gt;&lt;br&gt;Regarding the games thing, you might be right, although given a specific example there might be a workaround.  &lt;br&gt;&lt;br&gt;Regarding hooking into the message loop, any class can implement IMessageFilter and respond to a particular window message.&lt;br&gt;&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsimessagefilterclasstopic.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsimessagefilterclasstopic.asp&lt;/a&gt;&lt;br&gt;&lt;br&gt;See all about handles in windows forms as it may have some more tips for you here..&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/jfoscoding/archive/2004/11/24/269416.aspx"&gt;http://blogs.msdn.com/jfoscoding/archive/2004/11/24/269416.aspx&lt;/a&gt;&lt;br&gt;</description></item><item><title>Keeping your UI Responsive and the Dangers of Application.DoEvents</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#452103</link><pubDate>Tue, 16 Aug 2005 14:26:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:452103</guid><dc:creator>Link Blog</dc:creator><description>jfo's coding : Keeping your UI Responsive and the Dangers of Application.DoEvents&lt;br&gt;What&amp;amp;amp;rsquo;s the difference...</description></item><item><title>re: Keeping your UI Responsive and the Dangers of Application.DoEvents</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#452193</link><pubDate>Tue, 16 Aug 2005 18:44:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:452193</guid><dc:creator>Vladimir Klisic</dc:creator><description>Thanks Jessica,&lt;br&gt;&lt;br&gt;Actually I had the ApplicationContext in mind but I was in a short intellectual coma when I was writing my question. &lt;br&gt;&lt;br&gt;Here's what I really wanted to ask: assuming that I do pass an ApplicationContext to a second thread (see the code below), are there any threading or other issues if both threads wait for the same (main) Form to close (within their respective Application.Run calls)?&lt;br&gt;&lt;br&gt;Code:&lt;br&gt;&lt;br&gt;&amp;lt;main thread&amp;gt;&lt;br&gt;static void Main() &lt;br&gt;{ &lt;br&gt;  MyMainForm mainForm = new MyMainForm();&lt;br&gt;  ApplicationContext applicationContext = new ApplicationContext(mainForm);&lt;br&gt;  &lt;br&gt;  // Create second thread&lt;br&gt;  // Pass applicationContext to that thread, or somehow made it accessible from there&lt;br&gt;  &lt;br&gt;  Application.Run();  // or Application.Run(mainForm), I guess it doesn't make a difference (?)&lt;br&gt;  ...&lt;br&gt;}&lt;br&gt;&lt;br&gt;&amp;lt;second thread&amp;gt;&lt;br&gt;// Somewhere in the code, wait for the main form to close&lt;br&gt;&lt;br&gt;  Application.Run(applicationContext);  // same app context created in main()&lt;br&gt;</description></item><item><title>re: Keeping your UI Responsive and the Dangers of Application.DoEvents</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#452254</link><pubDate>Tue, 16 Aug 2005 20:32:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:452254</guid><dc:creator>jfoscoding</dc:creator><description>Vladimir: I would hesitate to pass the same application context to a different thread - while I dont know of any issues offhand, it was not designed to be thread-safe: e.g. no one's taking locks at appropriate times. &lt;br&gt;&lt;br&gt;It's probably safer to roll your own application context here for the second thread.</description></item><item><title>Keeping your UI Responsive and the Dangers of Application.DoEvents</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#453286</link><pubDate>Fri, 19 Aug 2005 01:06:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:453286</guid><dc:creator>Link Blog</dc:creator><description>jfo's coding : Keeping your UI Responsive and the Dangers of Application.DoEvents&lt;br&gt;Whats the difference...</description></item><item><title>Starting an application without showing a form</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#455580</link><pubDate>Wed, 24 Aug 2005 17:42:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:455580</guid><dc:creator>jfo's coding</dc:creator><description>There were a lot of good comments/questions about keeping your UI responsive, if you're interested in...</description></item><item><title>Articles as seen on jfo's coding</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#458762</link><pubDate>Thu, 01 Sep 2005 02:27:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:458762</guid><dc:creator>jfo's coding</dc:creator><description>Custom PaintingPainting best practices ComboBox OwnerDrawLayoutDock layout/Using the Splitter control...</description></item><item><title>A Nifty Comment Toggling Technique</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#462028</link><pubDate>Wed, 07 Sep 2005 20:50:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:462028</guid><dc:creator>Craig : Geek, IBlogger</dc:creator><description>When reading someone else's blog (even when searching for the answer to a specific problem) occasionally...</description></item><item><title>Application.DoEvents</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#777572</link><pubDate>Sat, 30 Sep 2006 02:53:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:777572</guid><dc:creator>Ricky Tan, .NET Framework Client Team</dc:creator><description>While doing the Vista Test Pass, I noticed a lot of timing and synchronization issues in the tests, and...</description></item><item><title>Phil Bernie Consulting &amp;raquo; Disabling MDAs (Managed Debugging Assistant) </title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#3985111</link><pubDate>Sat, 21 Jul 2007 08:11:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3985111</guid><dc:creator>Phil Bernie Consulting » Disabling MDAs (Managed Debugging Assistant) </dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://blog.pnbconsulting.com.au/?p=54"&gt;http://blog.pnbconsulting.com.au/?p=54&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>Intel?? Software Network Blogs  &amp;raquo; Parallel FX &amp;#038; Threading for newbies (like me.)</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#7046050</link><pubDate>Thu, 10 Jan 2008 01:04:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7046050</guid><dc:creator>Intel?? Software Network Blogs  » Parallel FX &amp; Threading for newbies (like me.)</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://softwareblogs.intel.com/2008/01/09/parallel-fx-threading-for-newbies-like-me/"&gt;http://softwareblogs.intel.com/2008/01/09/parallel-fx-threading-for-newbies-like-me/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>Windows &amp;raquo; jfo&amp;#8217;s coding : Keeping your UI Responsive and the Dangers of&amp;#8230;</title><link>http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx#8477046</link><pubDate>Fri, 09 May 2008 07:03:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8477046</guid><dc:creator>Windows &amp;raquo; jfo&amp;#8217;s coding : Keeping your UI Responsive and the Dangers of&amp;#8230;</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://windows.wawblog.info/?p=13087"&gt;http://windows.wawblog.info/?p=13087&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>