Backgroundworker

T

Tony Johansson

Hi!

The reason a I read this book is because it is associated with the exam
70-536.

I know that abort a thread might not be the best option.
If I have a Backgroundworker object then I can use the CancelAsync on it.

I just wonder is this CancelAsync the same for a Backgroundworker
as Abort is for a thread ?

I would believe.

//Tony
 
P

Patrice

Hello,
I just wonder is this CancelAsync the same for a Backgroundworker
as Abort is for a thread ?

Depends on your point of view but I would say no :
- CancelAsync is a pattern that allows to end a backgroundworker based
thread in a clean way.
- Abort doesn't end the thread in a clean way and should be avoided

So IMO they can't be considered the same as one is legitimate and the other
should be avoided...
 
P

Peter Duniho

Tony said:
Hi!

The reason a I read this book is because it is associated with the exam
70-536.

I know that abort a thread might not be the best option.
If I have a Backgroundworker object then I can use the CancelAsync on it.

I just wonder is this CancelAsync the same for a Backgroundworker
as Abort is for a thread ?

As Patrice says, it depends on your definition of "the same". They do
accomplish similar results, but there are very significant differences
between the two techniques, in how the client code uses them as well as
in the exact mechanism by which it allows a thread to stop.

In general, the mechanism and API pattern used for
BackgroundWorker.CancelAsync() is a good one to follow, even if you're
not using BackgroundWorker (of couse you would have to implement the
flag, property, etc. yourself but it's not that difficult if you already
know how to write multi-threaded code).

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top