Re: Delegate.BeginInvoke and EndInvoke.
"Bhatnagar, Amit" <[email protected]> Tue, 15 Jan 2008 13:59:34 -0700
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <[email protected]> |
grr.. I was just missing a=20 using System.Runtime.Remoting.Messaging=20 statement. -----Original Message----- From: Discussion forum for developers using Windows Forms to build apps and controls [mailto:[email protected]] On Behalf Of Bhatnagar, Amit Sent: Tuesday, January 15, 2008 1:53 PM To: [email protected] Subject: Re: [DOTNET-WINFORMS] Delegate.BeginInvoke and EndInvoke. When I try calling EndInvoke in the AsyncCallback, as described on page 2 of Richard's example, I get an InvalidCastException when trying to cast the AsyncState to my delegate. He shows a work around (Code Example 11), but that doesn't seem to work on the 2.0 version of the framework. Any ideas?=20 -----Original Message----- From: Discussion forum for developers using Windows Forms to build apps and controls [mailto:[email protected]] On Behalf Of Peter Ritchie Sent: Tuesday, January 15, 2008 11:43 AM To: [email protected] Subject: Re: [DOTNET-WINFORMS] Delegate.BeginInvoke and EndInvoke. In Richard's example (pg 2), he shows using the BeginInvoke overload that takes the AsyncCallback which calls some method when the call completes. In there, as Richard details, you can call EndInvoke. The AsyncCallback is called on a ThreadPool thread. If you're looking to avoid stress on the threadpool, using your own thread to wait on the wait handle may be a better option. Using the AsyncCallback means creating a type to keep track of the delegate reference in order to call its BeginInvoke. It's up to you how complicated you want to be if stressing the threadpool isn't an issue. Peter's example has a leak. The information contained in this e-mail message is PRIVATE. It may contain confidential information and may be legally privileged. It is intended for the exclusive use of the addressee(s). If you are not the intended recipient, you are hereby notified that any dissemination, distribution or reproduction of this communication is strictly prohibited. If the intended recipient(s) cannot be reached or if a transmission problem has occurred, please notify the sender immediately by return e-mail and destroy all copies of this message.=20 Thank you.=20