Re: Thread
- From: "mehdi" <mehdi.mousavi@xxxxxxxxx>
- Date: 18 Feb 2007 02:06:18 -0800
On Feb 15, 12:05 pm, "mehdi" <mehdi.mous...@xxxxxxxxx> wrote:
On Feb 15, 10:58 am, "Marc Gravell" <marc.grav...@xxxxxxxxx> wrote:
Of course, as Peter observes, a simpler approach can be to simple fire
the events on the current thread, and make it clear to the caller that
the event will fire on an arbitrary thread and that they must
therefore deal with sync themselves locally - e.g. by using
InvokeRequired / BeginInvoke / Invoke at the caller ;-p
Additional note: using the synchronizing object approach (my last
post) you could also test InvokeRequired before firing the event -
e.g. the first block would become (leaving the rest unchanged):
if (_syncInvoke == null || !_syncInvoke.InvokeRequired)
{ // no sync context (have to run sync) or synchronize not
necessary
handler(this, EventArgs.Empty);
}
Marc
Well, I really enjoyed the ISynchronizeInvoke interface. However, I'm
still confused about the provided code.
1. What if I never ever call the "Invoke" method?
2. What exactly Control.BeginInvoke does?
3. What does Control.EndInvoke do? Is is just supposed to get the
return value of an asynchronous function?
Any help would be highly appreciated,
Cheers,
Mehdi
For those who are familiar with Win32, the short answer is that
Control.BeginInvoke actually calls the PostMessage API, while the
Invoke method calls the SendMessage API.
HTH,
Mehdi
.
- References:
- Thread
- From: mehdi
- Re: Thread
- From: Marc Gravell
- Re: Thread
- From: Marc Gravell
- Re: Thread
- From: mehdi
- Thread
- Prev by Date: Re: VS2005 loses tabs when pasting
- Next by Date: Re: compile dll with calls to methods that dont exit yet
- Previous by thread: Re: Thread
- Next by thread: How to write in C# to check FTP connect or not?
- Index(es):
Relevant Pages
|