Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / January 2006

Tip: Looking for answers? Try searching our database.

Asynch execution - EndInvoke

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jon Shemitz - 10 Jan 2006 22:14 GMT
The dox are very emphatic that when you use a delegate's BeginInvoke,
you must always call the delegate's EndInvoke:

> Important  
> Always call EndInvoke to complete your asynchronous call.

That's 2.0; 1.1 is different, but similar.

Why? The debugger shows that the IAsynchResult that BeginInvoke
returns has a ManualResetEvent, which inherits a finalizer from
WaitHandle. So, why the emphasis on calling EndInvoke?

It almost sounds as if the IAsynchResult is stored in a list
somewhere, and so will never finalize. But the VS debugger won't go
into BeginInvoke / EndInvoke's
native code, so I can't look ....

Signature

    <http://www.midnightbeach.com>

Richard Grimes [MVP] - 30 Jan 2006 13:38 GMT
> The dox are very emphatic that when you use a delegate's BeginInvoke,
> you must always call the delegate's EndInvoke:
[quoted text clipped - 12 lines]
> into BeginInvoke / EndInvoke's
> native code, so I can't look ....

Your code will run in some .NET context, an object can require more than
one context, and these occur as a chain, with the results from one
context being passed on to the next context handler.

Thus every method call, sync or async, will go through a chain of
context objects and each context will be allowed to handle the method
call in whatever way it likes. So one context may cache some objects
when the async call is started and this context handler will only
release those cached objects when you call EndInvoke. Of course, in most
cases, with objects run in the same application domain and accessed by a
single thread, you'll only have the standard context so for methods that
do not return results you may as well omit the call to EndInvoke.
However, this is not a good idea because if at a later state you decide
to run your object under COM+ or some other environment then .NET (or
another developer) may add a context.

It's a good habit to call EndInvoke. However, if you write the method
that is called asynchronously then you can indicate to .NET contexts
that callers won't call EndInvoke by using the [OneWay] attribute.

Richard
Signature

Fusion Tutorial: http://www.grimes.demon.co.uk/workshops/fusionWS.htm
Security Tutorial:
http://www.grimes.demon.co.uk/workshops/securityWS.htm

Jon Shemitz - 30 Jan 2006 23:32 GMT
> Your code will run in some .NET context, an object can require more than
> one context, and these occur as a chain, with the results from one
[quoted text clipped - 11 lines]
> to run your object under COM+ or some other environment then .NET (or
> another developer) may add a context.

Thank you - this makes sense. However, while I may have misunderstood
Don Box's Ch 7, I thought that contexts and context switches and the
whole method-calls-as-messaging model only applied to classes that
inherit from ContextBoundObject?

> It's a good habit to call EndInvoke. However, if you write the method
> that is called asynchronously then you can indicate to .NET contexts
> that callers won't call EndInvoke by using the [OneWay] attribute.

But [OneWay] makes no guarantees, right? It's merely a post-MS (ie,
not even hinted at in the dox) convention, that various context may or
may not honor?

Signature

    <http://www.midnightbeach.com>


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.