CODE
if (bgw.CancellationPending)
return;
return;
all over the place, there are way to break background worker?
I like minimal code
.NET Background Worker, C# reduce code CancellationPending
|
Jul 3 2015, 04:10 PM, updated 9y ago
Show posts by this member only | Post
#1
|
Senior Member
1,917 posts Joined: Jul 2009 From: /dev/null |
Inside my Background worker has multiple for and foreach loop, I had to place this
CODE if (bgw.CancellationPending) return; all over the place, there are way to break background worker? I like minimal code |
|
|
|
Jul 3 2015, 06:06 PM
Show posts by this member only | Post
#2
|
Junior Member
429 posts Joined: Dec 2012 From: Kitchen |
Hi ilham
|
|
Jul 3 2015, 07:43 PM
Show posts by this member only | Post
#3
|
Senior Member
1,917 posts Joined: Jul 2009 From: /dev/null |
What?
|
|
Jul 13 2015, 10:14 AM
Show posts by this member only | Post
#4
|
Junior Member
111 posts Joined: Jan 2003 |
Hi,
Not much input can be offered without any code snippet. Checking CancellationPending is the correct way though for me I won't just return/break but to set the e.Cancel to true so you can use it in RunWorkerCompleted to do the necessary follow up something like this CODE if (bgw.CancellationPending) { e.Cancel = true; return/break; } bgw.RunWorkerCompleted += (s, e) => { if (e.Cancelled){ .. the follow up action ... } } { |
Change to: | 0.0115sec
0.09
5 queries
GZIP Disabled
Time is now: 29th March 2024 - 01:02 AM |