﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Alex Simkin commented on Talk about nasty bugs</title><description>This is actally in the docs:
  
  
You must manually keep the delegate from being collected by the garbage collector from managed code. The garbage collector does not track reference to unmanaged code.
  
  
See: 
[msdn.microsoft.com/.../...npointerfordelegate.aspx](http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getfunctionpointerfordelegate.aspx)  
</description><link>http://ayende.com/4485/talk-about-nasty-bugs#comment14</link><guid>http://ayende.com/4485/talk-about-nasty-bugs#comment14</guid><pubDate>Wed, 05 May 2010 19:39:45 GMT</pubDate></item><item><title>Ayende Rahien commented on Talk about nasty bugs</title><description>Yes, it does.
  
The only important thing is that it isn't rooted
</description><link>http://ayende.com/4485/talk-about-nasty-bugs#comment13</link><guid>http://ayende.com/4485/talk-about-nasty-bugs#comment13</guid><pubDate>Wed, 05 May 2010 06:08:32 GMT</pubDate></item><item><title>Laurion Burchall commented on Talk about nasty bugs</title><description>Hmmm, looks familiar ;-)
  
  
Is this actually broken with a static method as well as member methods? What does reflector say the actual code looks like?
</description><link>http://ayende.com/4485/talk-about-nasty-bugs#comment12</link><guid>http://ayende.com/4485/talk-about-nasty-bugs#comment12</guid><pubDate>Wed, 05 May 2010 04:04:20 GMT</pubDate></item><item><title>Martin commented on Talk about nasty bugs</title><description>I suspect that if you were to run this on Mono, you WOULDN'T see this problem because it employs a conservative GC.
</description><link>http://ayende.com/4485/talk-about-nasty-bugs#comment11</link><guid>http://ayende.com/4485/talk-about-nasty-bugs#comment11</guid><pubDate>Tue, 04 May 2010 23:49:05 GMT</pubDate></item><item><title>dave-ilsw commented on Talk about nasty bugs</title><description>1. I've never used Marshall methods. I take it that the GetFunctionPointerForDelegate method causes the callback method to be invoked in a thread-safe manner?
  
  
2. What is the solution? Make var lpProgressRoutineIntPtr a class variable instead of a local?
</description><link>http://ayende.com/4485/talk-about-nasty-bugs#comment10</link><guid>http://ayende.com/4485/talk-about-nasty-bugs#comment10</guid><pubDate>Tue, 04 May 2010 22:49:22 GMT</pubDate></item><item><title>tobi commented on Talk about nasty bugs</title><description>The reason why it only crashes if there is additional work done is that the garbage collector only runs if an allocation occurs.
</description><link>http://ayende.com/4485/talk-about-nasty-bugs#comment9</link><guid>http://ayende.com/4485/talk-about-nasty-bugs#comment9</guid><pubDate>Tue, 04 May 2010 22:23:43 GMT</pubDate></item><item><title>Phil commented on Talk about nasty bugs</title><description>Dude! You blog so much that I wonder how you ever get work done. 
</description><link>http://ayende.com/4485/talk-about-nasty-bugs#comment8</link><guid>http://ayende.com/4485/talk-about-nasty-bugs#comment8</guid><pubDate>Tue, 04 May 2010 21:44:08 GMT</pubDate></item><item><title>Ayende Rahien commented on Talk about nasty bugs</title><description>OmariO &amp; Michael,
  
Wow, that was fast.
  
Yep that is the problem.
</description><link>http://ayende.com/4485/talk-about-nasty-bugs#comment7</link><guid>http://ayende.com/4485/talk-about-nasty-bugs#comment7</guid><pubDate>Tue, 04 May 2010 21:28:32 GMT</pubDate></item><item><title>Andrew commented on Talk about nasty bugs</title><description>You're not using a SafeHandle?
</description><link>http://ayende.com/4485/talk-about-nasty-bugs#comment6</link><guid>http://ayende.com/4485/talk-about-nasty-bugs#comment6</guid><pubDate>Tue, 04 May 2010 21:18:38 GMT</pubDate></item><item><title>John commented on Talk about nasty bugs</title><description>Could it be that you've got SetLastError set to true, are not calling GetLastWin32Error() anywhere, and when more than one thread is running there are errors trying to be set?
</description><link>http://ayende.com/4485/talk-about-nasty-bugs#comment5</link><guid>http://ayende.com/4485/talk-about-nasty-bugs#comment5</guid><pubDate>Tue, 04 May 2010 20:58:58 GMT</pubDate></item><item><title>Michael Davis commented on Talk about nasty bugs</title><description>Seconding that not keeping a reference to the delegate to prevent it from being garbage collected before CopyFileEx() is done with it could be a potential problem.  I've been burned by that before myself.
  
  
By the way, is there really a need to manually call Marshal.GetFunctionPointerForDelegate()?  I'm pretty sure I've been able to specify an actual delegate type in a P/Invoke signature and the framework handled the conversion on its own.
  
</description><link>http://ayende.com/4485/talk-about-nasty-bugs#comment4</link><guid>http://ayende.com/4485/talk-about-nasty-bugs#comment4</guid><pubDate>Tue, 04 May 2010 20:52:50 GMT</pubDate></item><item><title>dave-ilsw commented on Talk about nasty bugs</title><description>If you were updating a graphical progress bar, the call to update it would have to be invoked to avoid cross-threading issues. Does that also apply when writing to the console?
</description><link>http://ayende.com/4485/talk-about-nasty-bugs#comment3</link><guid>http://ayende.com/4485/talk-about-nasty-bugs#comment3</guid><pubDate>Tue, 04 May 2010 20:52:25 GMT</pubDate></item><item><title>OmariO commented on Talk about nasty bugs</title><description>I don't know how it related to threading but one of the reasons can be that you don't keep reference to the delegate. 
  
</description><link>http://ayende.com/4485/talk-about-nasty-bugs#comment2</link><guid>http://ayende.com/4485/talk-about-nasty-bugs#comment2</guid><pubDate>Tue, 04 May 2010 20:43:44 GMT</pubDate></item><item><title>Abc Dee commented on Talk about nasty bugs</title><description>static &amp; threading = trouble
</description><link>http://ayende.com/4485/talk-about-nasty-bugs#comment1</link><guid>http://ayende.com/4485/talk-about-nasty-bugs#comment1</guid><pubDate>Tue, 04 May 2010 20:41:35 GMT</pubDate></item></channel></rss>