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 pathasyncworkerprogress.html
More file actions
50 lines (43 loc) · 1.41 KB
/
asyncworkerprogress.html
File metadata and controls
50 lines (43 loc) · 1.41 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>Show Progress</h2>
<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[
DoWorkEventHandler worker = delegate(object sender, DoWorkEventArgs e)
{
AsyncWorker genericWorker = (AsyncWorker)sender;
genericWorker.WorkerReportsProgress = true;
for (int i = 0; i <= 100; i += 10)
{
genericWorker.ReportProgress(i, "current step = " + i);
}
};
ProgressChangedEventHandler progress = (sender, e) =>
{
// update UI with this data:
int percentage = e.ProgressPercentage;
object step = e.UserState;
};
AsyncWorker asyncWorker = new AsyncWorker(worker, progress, null);
asyncWorker.RunWorkerAsync();
]]></script>
<p>
The progress callback will be called on the thread on which the async worker was started if this thread supports synchronization (UI thread do support synchronization).
</p>