Differents Thread Classes

G

Guest

Hi

I'm Roby Eisenbraun Martins. I 'm a C#,VB,C++ developer.
I'm working with NET 2005 and I need a good thread control class.
Initialy I was working with "Thread" Class. It appears to be the best
class to work with threads, because it containg all the basic commands to
control a thread.
But It doesn't have a good performance and The debug mode doesn't work
very well when there is a thread from "Thread" class running. It is not able
to identify some threads errors correctly.
"BackgroundWorked" and "AsyncOperations" do a nice job, but in the
another hand, they don't have a real Cancel method.
Why there are differences between them and which one should I use to
work together with a form (UI)? don't forget about cross-thread error.

Thank you,
Roby Eisenbraun Martins
 
G

Guest

Hi,

One more thing. The BackgroundWorker has got a Completed event that
allows to make changes in the Forms without receiving the cross-thread error.
How can this be possible if in theory it is working in a different thread? Is
it executing the event in the main thread? How can this be possible?
And how can I work updating the form whenever the progress is posted
(ReportProgress)? I tried that but the performance is very pour and at the
same time the form get locked ( like working in a single thread). I think is
to much updates in a single time.

Thank you,
Roby Eisenbraun Martins


Thank you,
Roby Eisenbraun Martins
 
K

Kevin Spencer

Hi Roby,

You should check out the entire System.Threading namespace. Threading is
quite useful (as you know), and there is quite a lot of functionality
available in that namespace, beyond System.Threading.Thread.

As for debugging threads, I think you may not be aware of Visual
Studio.Net's thread debugging capabilities. You can certainly debug any and
all threads in an application while debugging it. I'm not sure what you mean
by "doesn't work very well," but I suspect you're not aware of the tools
available and/or how to use them.

The System.ComponentModel.BackgroundWorker class is quite useful in Windows
Forms applications. A .Net Windows Forms application is tricky with regards
to threading, because it is not truly multi-threaded. System.Windows.Form is
more or less a wrapper for the Single Threaded Apartment Windows API form.
So multi-threading in a Windows form app can be tricky, as to ensure that no
problems occur, one must use marshalling to get separate threads to
synchronize with the Form thread. This doesn't mean that you can't use the
System.Threading.Thread class in a Windows form app, but it is certainly
less difficult to do so.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
J

Jon Skeet [C# MVP]

Roby Eisenbraun Martins
I'm Roby Eisenbraun Martins. I 'm a C#,VB,C++ developer.
I'm working with NET 2005 and I need a good thread control class.
Initialy I was working with "Thread" Class. It appears to be the best
class to work with threads, because it containg all the basic commands to
control a thread.
But It doesn't have a good performance and The debug mode doesn't work
very well when there is a thread from "Thread" class running. It is not able
to identify some threads errors correctly.
"BackgroundWorked" and "AsyncOperations" do a nice job, but in the
another hand, they don't have a real Cancel method.
Why there are differences between them and which one should I use to
work together with a form (UI)? don't forget about cross-thread error.

I suggest you read through the whole of my article on threading:
http://www.pobox.com/~skeet/csharp/threads
 

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