BeginInvoke and EndInvoke - Is EndInvoke necessary?

R

Robert Conde

Hi,
I'm calling my ui from a thread which is different from the ui thread.
Accordingly I need to use the BeginInvoke or Invoke functions. Now I'd
rather the calls be non-blocking so I'd like to use BeginInvoke. But the
documentation says "CAUTION Always call EndInvoke after your asynchronous
call completes." Is this really necessary? I don't need a result. I just
want to use it like PostMessage. It's gonna be a pain to hold the asynch
result and call EndInvoke somehow. It seems to be working without calling
EndInvoke, but I don't want it creeping up on me later.

Rob Conde
a.i. solutions
 
H

Herfried K. Wagner [MVP]

* "Robert Conde said:
I'm calling my ui from a thread which is different from the ui thread.
Accordingly I need to use the BeginInvoke or Invoke functions. Now I'd
rather the calls be non-blocking so I'd like to use BeginInvoke. But the
documentation says "CAUTION Always call EndInvoke after your asynchronous
call completes." Is this really necessary? I don't need a result. I just
want to use it like PostMessage. It's gonna be a pain to hold the asynch
result and call EndInvoke somehow. It seems to be working without calling
EndInvoke, but I don't want it creeping up on me later.

Currently, you don't need to call 'EndInvoke', but maybe there will be
problems/leaks if you don't call it in future versions of .NET.
 
J

Jon Skeet [C# MVP]

Herfried K. Wagner said:
Currently, you don't need to call 'EndInvoke', but maybe there will be
problems/leaks if you don't call it in future versions of .NET.

Not for UI calls - I believe the WinForms team has basically guaranteed
that EndInvoke isn't required for UI calls. For all other async
Begin/EndXXX pairs, you should call EndXXX.
 

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