Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
swdev:dotnet:actions [2011/01/26 16:17] smayr [Using Actions to Communicate Between Background Worker and Main Threads] |
swdev:dotnet:actions [2011/01/26 16:55] (current) smayr [Example] |
||
---|---|---|---|
Line 40: | Line 40: | ||
* [[http:// | * [[http:// | ||
+ | == Example == | ||
+ | |||
+ | <code csharp> | ||
+ | /// | ||
+ | /// < | ||
+ | /// Close the popup menu. | ||
+ | /// </ | ||
+ | /// | ||
+ | public void Close() | ||
+ | { | ||
+ | // | ||
+ | // Deal with cross thread ownership of UI control instance | ||
+ | // by invoking an action delegate. In other words, | ||
+ | // popupmnu is owned by thread that instantiated it (when Open() was called), | ||
+ | // so we cannot close popmnu arbitrarily. | ||
+ | // the owner thread' | ||
+ | // | ||
+ | //Action action = () => popmnuReports.IsOpen = false; | ||
+ | Action action = this.CloseDelegate(); | ||
+ | this.Dispatcher.BeginInvoke(action); | ||
+ | } | ||
+ | |||
+ | /// | ||
+ | /// < | ||
+ | /// Close method deletegate, used by cross thread dispatcher. | ||
+ | /// </ | ||
+ | /// < | ||
+ | /// | ||
+ | private Action CloseDelegate() | ||
+ | { | ||
+ | return delegate() | ||
+ | { | ||
+ | popmnuFitting.IsOpen = false; | ||
+ | m_TimerForDisplay.Enabled = false; | ||
+ | }; | ||
+ | } | ||
+ | </ | ||
== Resources == | == Resources == | ||
* [[http:// | * [[http:// |