Permalink
Browse files

added async and user interface thread synchronizer

  • Loading branch information...
1 parent d7369ae commit 0e6732446878cd4c996cd89fe0dfed04784000a8 @ursenzler committed Apr 3, 2012
Showing with 75 additions and 0 deletions.
  1. +3 −0 _config.yml
  2. +14 −0 async.html
  3. +58 −0 userinterfacethreadsynchronizer.html
View
3 _config.yml
@@ -37,9 +37,12 @@ navigation:
- name: Evaluation Engine
link: evaluationengine.html
- name: Async
+ link: async.html
grandchildren:
- name: AsyncWorker
link: asyncworker.html
+ - name: User Interface Thread Synchronizer
+ link: userinterfacethreadsynchronizer.html
- name: State Machine
link: statemachine.html
- name: Road Map
View
14 async.html
@@ -0,0 +1,14 @@
+---
+layout: documentation
+title: EvaluationEngine
+teaser: Decouple business logic from control flow
+navigation:
+ - name: Async Worker
+ link: asyncworker.html
+ - name: User Interface Thread Synchronizer
+ link: userinterfacethreadsynchronizer.html
+---
+<h2>Async Components</h2>
+<p>
+The async package includes several components for asynchronous execution. See navigation on the right -&gt;
+</p>
View
58 userinterfacethreadsynchronizer.html
@@ -0,0 +1,58 @@
+---
+layout: documentation
+title: User Interface Thread Synchronizer
+teaser: Your quick way to execute some code on the user interface thread when you are working hard on a worker thread.
+navigation:
+ - name: Overview
+ link: userinterfacethreadsynchronizer.html
+---
+<h2>User Interface Thread Synchronizer</h2>
+<p>
+With the <code>UserInterfaceThreadSynchronizer</code> you can execute code on the user interface thread from any thread.
+This is usefull when an operation runs on a worker thread and needs for example to update a label on the UI or needs to create a UI component for later usage.
+</p>
+<p>
+The user interface thread synchronizer needs to be created on the user interface thread. Otherwise, it is not capable of switching to the user interface thread.
+</p>
+<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[
+var synchronizer = new UserInterfaceThreadSynchronizer();
+]]></script>
+<p>
+Later, you can use the user interface thread synchronizer to execute code on the UI thread:
+</p>
+<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[
+synchronizer.Execute(() => { /* this code will be executed on UI thread */ });
+]]></script>
+<p>
+This will block the worker thread and execute the action specified on the user interface thread.
+You can also pass up to four arguments to the <code>Execute</code> method:
+</p>
+<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[
+synchronizer.Execute(
+ (a, b) => { /* this code will be executed on UI thread */ },
+ 17,
+ 42);
+]]></script>
+<p>
+You can return values back to the worker thread:
+</p>
+<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[
+var result = synchronizer.Execute(() => { return 42; });
+]]></script>
+<p>
+And you can execute the action asynchronously. Obviously, it's not possible to return a value.
+</p>
+<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[
+synchronizer.ExecuteAsync(() => { /* executed asynchronously on UI thread */ });
+]]></script>
+
+<h3>Testability</h3>
+<p>
+For simpler tests, you can tell the user interface thread synchronizer to run synchronously by passing a <code>SyncrhonizationContext</code> in the constructor:
+</p>
+<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[
+var synchronizer = new UserInterfaceThreadSynchronizer(new SynchronisationContext());
+]]></script>
+<p>
+Now, all actiosn are executed synchronously when <code>Execute</code> or <code>ExecuteAsync</code> is called.
+</p>

0 comments on commit 0e67324

Please sign in to comment.