<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Multi-Threading</title>
        <link>http://mostlylucid.homeip.net/category/16.aspx</link>
        <description>Multi-Threading</description>
        <language>en-US</language>
        <copyright>Scott Galloway</copyright>
        <managingEditor>blogcomments@mostlylucid.co.uk</managingEditor>
        <generator>Subtext Version 2.0.0.0</generator>
        <item>
            <title>Threading update...what I actually do...</title>
            <link>http://mostlylucid.homeip.net/archive/2004/05/24/threading-update.what-i-actually-do.aspx</link>
            <description>&lt;p&gt;Should mention I suppose the I lied in yesterdays post on threading using .NET...mea cupla :-). In that post I mentioned using delegates for multi-threading and said that you always had to use EndInvoke to avoid a memory leak...well not quite, what i actually do is use the excellent &lt;a href="http://www.bearcanyon.com/dotnet/#FireAndForget"&gt;AsyncHelper class by Mike Woodring&lt;/a&gt;, this supports this syntax: &lt;/p&gt;&lt;p&gt;CalcAndDisplaySumDelegate d = new CalcAndDisplaySumDelegate(someCalc.Add);&lt;br /&gt;    AsyncHelper.FireAndForget(d, 2, 3);&lt;/p&gt;&lt;p&gt;No EndInvoke required as it takes care of this using a DynamicInvoke internally. Well, saves a few lines of code!&lt;br /&gt;&lt;/p&gt;&lt;img src="http://mostlylucid.homeip.net/aggbug/845.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Blog Author</dc:creator>
            <guid>http://mostlylucid.homeip.net/archive/2004/05/24/threading-update.what-i-actually-do.aspx</guid>
            <pubDate>Tue, 25 May 2004 00:03:00 GMT</pubDate>
            <wfw:comment>http://mostlylucid.homeip.net/comments/845.aspx</wfw:comment>
            <comments>http://mostlylucid.homeip.net/archive/2004/05/24/threading-update.what-i-actually-do.aspx#feedback</comments>
            <wfw:commentRss>http://mostlylucid.homeip.net/comments/commentRss/845.aspx</wfw:commentRss>
            <trackback:ping>http://mostlylucid.homeip.net/services/trackbacks/845.aspx</trackback:ping>
        </item>
        <item>
            <title>Delegate.BeginInvoke() and memory leaks...</title>
            <link>http://mostlylucid.homeip.net/archive/2003/11/19/delegate.begininvoke-and-memory-leaks.aspx</link>
            <description>&lt;p&gt;I'm getting increasingly involved in the world of Asynchrony and have been doing a bit of digging about into some of the pitfalls of multi-threading. &lt;br /&gt;I came across an interesting one today involving the use of BeginInvoke without a corresponding EndInvoke when using delegates...many books (including the one I'm using most right now, the excellent &lt;a href="http://www.amazon.co.uk/exec/obidos/ASIN/0596003471/mostlylucid-21"&gt;Programming .NET Components by Juval Lowy&lt;/a&gt;) mention that a good way to fire events asynchronously (i.e., not blocking) is to simple call BeginInvoke on the delegate - cool seems easy enough! &lt;br /&gt;Well, reading around a bit, I discovered &lt;a href="http://www.bearcanyon.com/dotnet/#FireAndForget"&gt;this by Mike Woodring&lt;/a&gt; which contains this statement: &lt;em&gt;"Starting with the 1.1 release of the .NET Framework, the SDK docs now carry a caution that mandates calling EndInvoke on delegates you've called BeginInvoke on in order to avoid potential leaks. This means you cannot simply "fire-and-forget" a call to BeginInvoke without the risk of running the risk of causing problems. " &lt;br /&gt;&lt;/em&gt;Now, I can't find the bit in the docs which says that, but &lt;a href="http://www.ondotnet.com/pub/a/dotnet/2003/02/24/asyncdelegates.html?page=2"&gt;another article &lt;/a&gt; at &lt;a href="http://www.ondotnet.com/dotnet/"&gt;O'Reilly&lt;/a&gt; mentions the same thing... Well, based on this evidence, it would seem to be a good idea to avoid this potential leak, luckily &lt;a href="http://www.bearcanyon.com/dotnet/#FireAndForget"&gt;Mike's stuff&lt;/a&gt; has a handily little helper class which supports the &lt;a href="http://www.bearcanyon.com/dotnet/#FireAndForget"&gt;'Fire and Forget idiom'&lt;/a&gt; - dead easy, now I can have lovely fire and forget calls without worrying about unintended leaks :-)&lt;/p&gt;
&lt;p&gt;&lt;font color="#ff0000"&gt;UPDATE:&lt;/font&gt; Found the doc reference, if you have MSDN it's &lt;a href="ms-help://MS.NETFrameworkSDKv1.1/cpguidenf/html/cpovrasynchronousprogrammingoverview.htm"&gt;here&lt;/a&gt;, if not the on-line version is &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpovrasynchronousprogrammingoverview.asp"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;img src="http://mostlylucid.homeip.net/aggbug/653.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Blog Author</dc:creator>
            <guid>http://mostlylucid.homeip.net/archive/2003/11/19/delegate.begininvoke-and-memory-leaks.aspx</guid>
            <pubDate>Thu, 20 Nov 2003 02:54:00 GMT</pubDate>
            <wfw:comment>http://mostlylucid.homeip.net/comments/653.aspx</wfw:comment>
            <comments>http://mostlylucid.homeip.net/archive/2003/11/19/delegate.begininvoke-and-memory-leaks.aspx#feedback</comments>
            <wfw:commentRss>http://mostlylucid.homeip.net/comments/commentRss/653.aspx</wfw:commentRss>
            <trackback:ping>http://mostlylucid.homeip.net/services/trackbacks/653.aspx</trackback:ping>
        </item>
        <item>
            <title>Memory Leak - solved - or 'When STAThread Goes Bad'</title>
            <link>http://mostlylucid.homeip.net/archive/2003/11/17/memory-leak---solved---or-when-stathread-goes-bad.aspx</link>
            <description>I posted a little while ago about an odd 'Memory Leak' I was having...well, after several days of trawling (and annoying &lt;a href="http://weblogs.asp.net/dwanta/"&gt;Data Wanta &lt;/a&gt;who's excellent email &lt;a href="http://www.aspnetemail.com/"&gt;component&lt;/a&gt; I was mistakenly blaming - sorry!), I finally found the answer! Turns out that the little [STAThread] attribute above the main class of the Comand Line app isn't so inoccuous after all - Dave pointed out &lt;a href="http://groups.google.com/groups?hl=en&amp;amp;lr=&amp;amp;ie=UTF-8&amp;amp;oe=UTF-8&amp;amp;frame=right&amp;amp;th=d80d655cf0d70930&amp;amp;seekm=ef9gTVwLDHA.1720%40TK2MSFTNGP11.phx.gbl#link1"&gt;this thread&lt;/a&gt; - apparently there's some sort of &lt;a href="http://groups.google.com/groups?hl=en&amp;amp;lr=&amp;amp;ie=UTF-8&amp;amp;oe=UTF-8&amp;amp;selm=eXa3ObcPDHA.3192%40tk2msftngp13.phx.gbl"&gt;bug in .NET&lt;/a&gt;  which can lead to what is effectively a leak when using multi-threading in a STAThreaded application!&lt;img src="http://mostlylucid.homeip.net/aggbug/647.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Blog Author</dc:creator>
            <guid>http://mostlylucid.homeip.net/archive/2003/11/17/memory-leak---solved---or-when-stathread-goes-bad.aspx</guid>
            <pubDate>Tue, 18 Nov 2003 07:40:00 GMT</pubDate>
            <wfw:comment>http://mostlylucid.homeip.net/comments/647.aspx</wfw:comment>
            <comments>http://mostlylucid.homeip.net/archive/2003/11/17/memory-leak---solved---or-when-stathread-goes-bad.aspx#feedback</comments>
            <wfw:commentRss>http://mostlylucid.homeip.net/comments/commentRss/647.aspx</wfw:commentRss>
            <trackback:ping>http://mostlylucid.homeip.net/services/trackbacks/647.aspx</trackback:ping>
        </item>
    </channel>
</rss>