Commit b62a86e

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-03-25 16:17:29
learning how to use the SynchronizationContext and AsyncOperationManager for ui synchronization in windows forms.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@107 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent 47cd045
Changed files (3)
trunk
product
trunk/product/MyMoney/Presentation/Views/core/ApplicationWindow.cs
@@ -1,4 +1,6 @@
 using System;
+using System.ComponentModel;
+using System.Threading;
 using System.Windows.Forms;
 using MoMoney.Infrastructure.Extensions;
 using MoMoney.Presentation.Resources;
@@ -15,11 +17,16 @@ namespace MoMoney.Presentation.Views.core
 
     public partial class ApplicationWindow : Form, IApplicationWindow
     {
+        protected readonly SynchronizationContext context;
+        AsyncOperation operation;
+
         public ApplicationWindow()
         {
             InitializeComponent();
             Icon = ApplicationIcons.Application;
             this.log().debug("created {0}", GetType());
+            context = SynchronizationContext.Current;
+            operation = AsyncOperationManager.CreateOperation(null);
         }
 
         public IApplicationWindow create_tool_tip_for(string title, string caption, Control control)
@@ -38,6 +45,8 @@ namespace MoMoney.Presentation.Views.core
         public IApplicationWindow top_most()
         {
             TopMost = true;
+            Focus();
+            BringToFront();
             return this;
         }
 
@@ -49,14 +58,16 @@ namespace MoMoney.Presentation.Views.core
 
         protected void on_ui_thread(Action action)
         {
-            if (InvokeRequired)
-            {
-                BeginInvoke(action);
-            }
-            else
-            {
-                action();
-            }
+            //context.Post(x => action(), new object());
+            operation.Post(x => action(), new object());
+            //if (InvokeRequired)
+            //{
+            //    BeginInvoke(action);
+            //}
+            //else
+            //{
+            //    action();
+            //}
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Presentation/Views/Shell/ApplicationShell.cs
@@ -27,18 +27,15 @@ namespace MoMoney.Presentation.Views.Shell
                           };
         }
 
-
         protected override void OnLoad(EventArgs e)
         {
             try_to_reduce_flickering();
-            TopMost = true;
-            Focus();
-            BringToFront();
+                //.top_most();
         }
 
         public void attach_to(IApplicationShellPresenter presenter)
         {
-            Closed += (sender, args) => presenter.shut_down(); 
+            Closed += (sender, args) => presenter.shut_down();
         }
 
         public void add(IDockedContentView view)
trunk/product/MyMoney/Presentation/Views/updates/CheckForUpdatesView.cs
@@ -1,4 +1,5 @@
-using System.Reflection;
+using System;
+using System.Reflection;
 using System.Windows.Forms;
 using MoMoney.Domain.Core;
 using MoMoney.Presentation.Model.updates;