Newbie question: Threading and Synchronization

  • Thread starter Thread starter pplppp
  • Start date Start date
P

pplppp

Hi I'm new to C# and I am facing some simple scenario when
1) on the UI I press a button which triggers some calculation but I
dun want the user to wait
2) I update a dataset and I want to send the changes to another
endpoint

In both cases I believe I need to sprawn a new thread to preform the
work in the background, but C# offers many ways and I'm not sure what
are the differences between them and pros and cons of each. So far, I
think the following options are possible:
1) simple Threading, create an instance of ThreadStart and run it
2) use the ThreadPool and Queue a work item
3) call BeginInvoke of a Windows.Forms.Control object. or declare an
asynchronous delegate

Also C# has many Threading objects to do synchronization.. where can I
find a good tutorial explaning the differences between them and when
to use which one?
 
Eric Gunnerson has a good discussion in his C# book on exactly this topic.

And Chris Sells has an example in his book (Windows Forms Programming in C#)
that is very, very close to what you are requesting. You could probably
paste his example code directly, if my memory is correct. Check out
http://www.sellsbrothers.com/writing/wfbook/.
 
Hello

I would use a ThreadPool and Queue a work item,
Don't use BeginInvoke of a Windows.Forms.Control, because this method will
actually perform the call on the thread that created the control. This is
useful sometimes, but I think in your case the user will wait.

Best regards,
Sherif
 
Back
Top