How necessary is EndInvoke after BeginInvoke really (in UI calls, now and forever)?

M

Max

Hi!

In <[email protected]> Jon Skeet [C#
MVP] said that he _believes_ that for UI calls the WinForms team has
_basically_ guaranteed that EndInvoke is not required after
BeginInvoke.

In my applications I only want to update some controls from other
threads most of the time and absolutly don't care about the result
(actually there is no result when I only want textBox.Text = "text").

Currently I put all IAsyncResults from the BeginInvoke call into an
ArrayList and use another thread to poll the IAsyncResults in this
array for .IsCompleted. If a call is completed I call EndInvoke on it
and remove it from the ArrayList. That sucks quite a bit (after all
it's _just_ for updating text or whatever on some controls!) but in
the end it might save my....

Is there something official from Microsoft that really guarantees me
that I do not have to call EndInvoke on UI calls?

thanks,
Max
 
C

Christoph Nahr

Is there something official from Microsoft that really guarantees me
that I do not have to call EndInvoke on UI calls?

I recall reading in some book or MSDN article that EndInvoke is only
necessary if the worker thread wants to retrieve a return value from
the BeginInvoke call. Can't remember where I read that, though...
 
G

Guest

I don't have any links (google should throw up a few) for you, but I can
confirm that you do not need to call EndInvoke for UI calls. The UI teams
implementation of Begin/EndInvoke is different to the rest of the framework,
meaning ommitting the call to EndInvoke does not have any adverse effects.

HTH
Dan
 
J

Jon Skeet [C# MVP]

Max said:
In <[email protected]> Jon Skeet [C#
MVP] said that he _believes_ that for UI calls the WinForms team has
_basically_ guaranteed that EndInvoke is not required after
BeginInvoke.

In my applications I only want to update some controls from other
threads most of the time and absolutly don't care about the result
(actually there is no result when I only want textBox.Text = "text").

Currently I put all IAsyncResults from the BeginInvoke call into an
ArrayList and use another thread to poll the IAsyncResults in this
array for .IsCompleted. If a call is completed I call EndInvoke on it
and remove it from the ArrayList. That sucks quite a bit (after all
it's _just_ for updating text or whatever on some controls!) but in
the end it might save my....

Is there something official from Microsoft that really guarantees me
that I do not have to call EndInvoke on UI calls?

Well, it's not very official, but:

http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx

See Chris Brumme's post labelled May 12, 2003 5:30PM:

<quote>
I just got the official word from the WinForms team. It is not
necessary to call Control.EndInvoke. You can call BeginInvoke in a
"fire and forget" manner with impunity.
</quote>
 

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