Re: Thread

Tech-Archive recommends: Fix windows errors by optimizing your registry



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

.



Relevant Pages

  • Re: Thread
    ... the event will fire on an arbitrary thread and that they must ... therefore deal with sync themselves locally - e.g. by using ... using the synchronizing object approach (my last ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Is MAPI multithread-friendly?
    ... After Sync, loop over an Folder to build up a List into Database. ... > Unlike Outlook API? ... In an arbitrary thread ... When initializing my addin I build a list of IMAPIFolders that I'm ...
    (microsoft.public.office.developer.com.add_ins)