<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Asynchronous operations, pinning</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx</link><description>One thing we tried to do with the CLR and FX is provide a consistent asynchronous programming model. To briefly recap the model, an API called XXX may also offer an async alternative composed of BeginXXX and EndXXX methods. Even if the class that implements</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>RE: Asynchronous operations, pinning</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#51386</link><pubDate>Wed, 07 May 2003 21:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:51386</guid><dc:creator>Ian Griffiths</dc:creator><description>So is System.Windows.Forms.Control.BeginInvoke part of this model?  This may seem like a stupid question, but actually I suspect the answer is &amp;quot;no&amp;quot;.

There are two forms of Control.BeginInvoke, and *neither* of them lets you pass the optional callback delegate.  (You may ask &amp;quot;what about the first parameter - isn't that a delegate?&amp;quot; And the answer is &amp;quot;Yes, but that parameter is also there in the synchronous Invoke method - the async BeginXxx method is supposed to add an extra delegate according to this pattern.&amp;quot;)

This is aggravating as it makes it really awkward to call EndInvoke. You can't do it in the method called by the delegate passed in, because you'll then be saying &amp;quot;Please block until I return from the method I'm calling you from&amp;quot; - or to put it more succinctly &amp;quot;Please deadlock&amp;quot;.  So how are you supposed to call EndInvoke?  Using a call to Delegate.BeginInvoke?  Seems rather tedious...

So, given that Control.BeginInvoke does not appear to fit into the normal .NET pattern for async invocation, does this mean we're off the hook with respect to calling EndInvoke?</description></item><item><title>RE: Asynchronous operations, pinning</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#51387</link><pubDate>Wed, 07 May 2003 22:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:51387</guid><dc:creator>Chris Brumme</dc:creator><description>Last night I sent an email to the WinForms folks asking this same question.  Like you, I suspect the EndInvoke is optional on Control.  (I looked through the code, but that's no substitute for a statement from the authors).  As you say, this API doesn't quite match the managed async programming model anyway.

I'll reply back as soon as I get official word.</description></item><item><title>RE: Asynchronous operations, pinning</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#51388</link><pubDate>Thu, 08 May 2003 04:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:51388</guid><dc:creator>Dmitriy Zaslavskiy</dc:creator><description>Chris could you provide some examples of unnecessary pinning.</description></item><item><title>RE: Asynchronous operations, pinning</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#51389</link><pubDate>Thu, 08 May 2003 05:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:51389</guid><dc:creator>Chris Brumme</dc:creator><description>I've seen a lot of people pinning Delegate instances, as I described above.  I'm not aware of a circumstance where this makes sense.

I've also seen apps explicitly pinning managed arrays of primitives like char arrays and int arrays, before making PInvoke calls.  The same thing with String and StringBuilder objects.  If the unmanaged callee only needs access to the buffer for the life of the call, then the PInvoke marshaling layer will generally pin it for that duration.  So this can be a second example of unnecessary pinning.</description></item><item><title>RE: Asynchronous operations, pinning</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#51390</link><pubDate>Thu, 08 May 2003 08:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:51390</guid><dc:creator>Manoj</dc:creator><description>One of the issues with asynchronous execution is how impersonation works. 

Client request comes in, gets queued for async execution, worker thread picks up the request, now worker thread need to impersonate the client...</description></item><item><title>RE: Asynchronous operations, pinning</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#51391</link><pubDate>Thu, 08 May 2003 17:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:51391</guid><dc:creator>Dmitriy Zaslavskiy</dc:creator><description>Chris thanks, for your answer. But those examples where shown in tones of samples. What about class(es) containing arrays, will those get pinned as well?</description></item><item><title>RE: Asynchronous operations, pinning</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#51392</link><pubDate>Fri, 09 May 2003 04:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:51392</guid><dc:creator>Chris Brumme</dc:creator><description>Dmitriy,

Generally, PInvoke will either copy your data to fixed memory outside the GC heap, or it will pin memory in the GC heap and expose those bytes directly to unmanaged code.  In either case, you don't need to explicitly pin -- so long as access to these bytes is scoped to within the duration of the PInvoke call.
</description></item><item><title>RE: Asynchronous operations, pinning</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#51393</link><pubDate>Fri, 09 May 2003 04:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:51393</guid><dc:creator>Chris Brumme</dc:creator><description>Manoj,

I will be posting a new blog later this evening which discusses impersonation (a little) and transference of CAS information across async points (a lot).
</description></item><item><title>RE: Asynchronous operations, pinning</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#51394</link><pubDate>Fri, 09 May 2003 16:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:51394</guid><dc:creator>Dmitriy Zaslavskiy</dc:creator><description>Thanks Chris.
I think I got it now. </description></item><item><title>RE: Asynchronous operations, pinning</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#51395</link><pubDate>Tue, 13 May 2003 00:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:51395</guid><dc:creator>Chris Brumme</dc:creator><description>I just got the official word from the WinForms team.  It is not necessary to call Control.EndInvoke.  You can call BeginInvoke in a &amp;quot;fire and forget&amp;quot; manner with impunity.</description></item><item><title>re: Asynchronous operations, pinning</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#57888</link><pubDate>Mon, 12 Jan 2004 19:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:57888</guid><dc:creator>Sharpie</dc:creator><description>Regarding the advice to call EndInvoke on all delegates or face potential resource leakage, I believe this was poorly conveyed in the docs until 1.1, and even then only barely mentioned.&lt;br&gt;&lt;br&gt;Be that as it may, can you not get around this limitation for Fire and Forget by using the [OneWay] attribute on your delegate? I believe that attribute optimizes away the baggage of a fire and forget async delegate by preventing the runtime from having to carry around the IAsyncResult, the potential exception instance and the state object. So in short it kind of eliminates not only the concern of leakage but most of what it would leak anyway, and one would expect that if you had numerous such delegates, you'd be putting less strain on the resources. Presumably these are for operations for which don't throw exceptions or for which you don't care about their end result.&lt;br&gt;&lt;br&gt;Incidentally, if that doesn't solve it and you still want to program with a fire and forget model, Mike Woodard of Developmentor implemented a smart class that takes care of calling EndInvoke for you. It is not the most performant thing but in small doses it could solve your fire and forget blues.&lt;br&gt;&lt;br&gt;But something tells me that [OneWay] should take care of that for you, no?</description></item><item><title>re: Concurrency, Part 13 - Concurrency and the CLR</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#402316</link><pubDate>Fri, 25 Mar 2005 22:33:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:402316</guid><dc:creator>Larry Osterman's WebLog</dc:creator><description /></item><item><title>Introducing ICommunicationObject</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#538050</link><pubDate>Thu, 23 Feb 2006 22:02:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:538050</guid><dc:creator>Nicholas Allen's Indigo Blog</dc:creator><description>In the Windows Communication Foundation, there are a few classes that are so fundamental that they are...</description></item><item><title>blogging @ kafazov.net  &amp;raquo; Blog Archive   &amp;raquo; WinForms asyncronous programming model??????????????????? ????????????????????? ?? WinForms</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#1859114</link><pubDate>Sun, 11 Mar 2007 16:05:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1859114</guid><dc:creator>blogging @ kafazov.net  » Blog Archive   » WinForms asyncronous programming model??????????????????? ????????????????????? ?? WinForms</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://kafazov.net/blog/?p=116"&gt;http://kafazov.net/blog/?p=116&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>ASP.NET Tip: How to avoid creating a GC Hole</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#8964974</link><pubDate>Thu, 25 Sep 2008 15:52:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8964974</guid><dc:creator>ASP.NET Debugging</dc:creator><description>&lt;p&gt;There are only a few things that can make a .NET process crash.&amp;amp;#160; The most common one is an Unhandled&lt;/p&gt;
</description></item><item><title>EndInvoke still required? | keyongtech</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#9362050</link><pubDate>Thu, 22 Jan 2009 06:24:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9362050</guid><dc:creator>EndInvoke still required? | keyongtech</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.keyongtech.com/433557-endinvoke-still-required"&gt;http://www.keyongtech.com/433557-endinvoke-still-required&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>.NET Memory Management and GCHandle</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#9452209</link><pubDate>Sun, 01 Mar 2009 10:59:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9452209</guid><dc:creator>From .NET Geek's Desk</dc:creator><description>&lt;p&gt;GC Handle provides facilities to explicitly control and monitor the lifetime of an object in heap.Whenever&lt;/p&gt;
</description></item><item><title> cbrumme s WebLog Asynchronous operations pinning | Insomnia Cure</title><link>http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx#9719967</link><pubDate>Wed, 10 Jun 2009 04:00:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9719967</guid><dc:creator> cbrumme s WebLog Asynchronous operations pinning | Insomnia Cure</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://insomniacuresite.info/story.php?id=3245"&gt;http://insomniacuresite.info/story.php?id=3245&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>