BackgroundWorker vs. Asynch delegate method and BeginInvoke thread

G

Guest

Hello,

I need to create a background thread and two (or more) options are available
to me:

1. BackgroundWorker
2. Asynch delegate method and BeginInvoke

What are the differences between them in performance, complexity etc.

Thanks,
EitanB
 
C

Carl Daniel [VC++ MVP]

Eitan said:
Hello,

I need to create a background thread and two (or more) options are
available to me:

1. BackgroundWorker
2. Asynch delegate method and BeginInvoke

What are the differences between them in performance, complexity etc.

BackgroundWorker is easier. Unless you have some specific reason to not use
it, that's probably your best choice.

Async delegate uses the thread pool just as BackgroundWorker does, but it's
harder to use, will have no difference in performance, and is more complex.

-cd
 
G

Guest

Carl, Tanks
EitanB

Carl Daniel said:
BackgroundWorker is easier. Unless you have some specific reason to not use
it, that's probably your best choice.

Async delegate uses the thread pool just as BackgroundWorker does, but it's
harder to use, will have no difference in performance, and is more complex.

-cd
 
N

Nicholas Paldino [.NET/C# MVP]

I disagree. If you want to just execute an action, without cancelling
or notification while that action is performing on another thread, then I
would say using an asynchronous delegate call, the Thread class, or the
ThreadPool is much easer than the BackgroundWorker class.

If you need updates from the background thread, and/or the ability to
cancel, then the BackgroundWorker is the best option.
 
G

Guest

Hello,

Thanks for your anser.

My thead will communicate (send command/recieve status) through the
Ethernet. The status is a byte array, which I need to display on the screen.

EitanB

Nicholas Paldino said:
I disagree. If you want to just execute an action, without cancelling
or notification while that action is performing on another thread, then I
would say using an asynchronous delegate call, the Thread class, or the
ThreadPool is much easer than the BackgroundWorker class.

If you need updates from the background thread, and/or the ability to
cancel, then the BackgroundWorker is the best option.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Carl Daniel said:
BackgroundWorker is easier. Unless you have some specific reason to not
use it, that's probably your best choice.

Async delegate uses the thread pool just as BackgroundWorker does, but
it's harder to use, will have no difference in performance, and is more
complex.

-cd
 
C

Carl Daniel [VC++ MVP]

Nicholas said:
I disagree. If you want to just execute an action, without
cancelling or notification while that action is performing on another
thread, then I would say using an asynchronous delegate call, the
Thread class, or the ThreadPool is much easer than the
BackgroundWorker class.

Then you agree. In the case you describe, you have a specific reason not to
use BackgroundWorker - your use case does not fit well with the
BackgroundWorker model.

-cd
 

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