How to terminate a managed thread blocked in unmanaged code?
        Posted  
        
            by James Curran
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by James Curran
        
        
        
        Published on 2010-04-23T17:03:02Z
        Indexed on 
            2010/04/23
            18:03 UTC
        
        
        Read the original article
        Hit count: 238
        
I have a managed thread which is waiting, blocked, in an unmanaged code (specifically, it on a call to NamedPipeServerStream.WaitForConnection() which ultimitely calls into unmanaged code, and does not offer a timeout).
I want to shut the thread down neatly.
Thread.Abort() has no effect until the code returns to the managed realm, which it won't do until a client makes a connection, which we can't wait for).
I need a way "shock" it out of the unmanaged code; or a way to just kill the thread even while it's in unmanaged land.
© Stack Overflow or respective owner