This repository was archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathasyncworkerasyncoperation.html
More file actions
50 lines (44 loc) · 1.49 KB
/
asyncworkerasyncoperation.html
File metadata and controls
50 lines (44 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
---
layout: documentation
title: EvaluationEngine
teaser: Decouple business logic from control flow
navigation:
- name: Overview
link: asyncworker.html
- name: Execute asynchronous operation
link: asyncworkerasyncoperation.html
- name: Execute code on completion
link: asyncworkercompletion.html
- name: Exception Handling
link: asyncworkerexceptionhandling.html
- name: Cancel asynchronous operation
link: asyncworkercancel.html
- name: Use progress
link: asyncworkerprogress.html
- name: Testability
link: asyncworkertestability.html
---
<h2>Execute Asynchronous Operation</h2>
<p>
Instantiate an async worker and call <code>RunWorkerAsync</code> to start execution of the worker delegate on a background thread.
</p>
<h3>Simple Async Operation</h3>
<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[
DoWorkEventHandler worker = delegate
{
// take your time to do something because you will not block anyone...
};
AsyncWorker asyncWorker = new AsyncWorker(worker);
asyncWorker.RunWorkerAsync();
]]></script>
<h3>Async Operation with Arguments</h3>
<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[
DoWorkEventHandler worker = delegate(object sender, DoWorkEventArgs e)
{
// do something with the argument
//(unfortunately not type safe - please blame .net and not me)
string argument = (string)e.Argument;
};
AsyncWorker asyncWorker = new AsyncWorker(worker);
asyncWorker.RunWorkerAsync("hello world");
]]></script>