none
current thread is in a sleep, wait, or join

    Question

  • Code Snippet

    I've got this code. It pertains my attempt to set up NamedPipes. I've got as far as sending unlimited number of messages from Server to Client. However, when I try to send a message from Client to Server I get in trouble with the thread where the Client is located. I put the client in the thread with a ThreadStart delegate. I also have a global List that keeps references to all threads I set up in this app. Thus I can access a thread in the client method and see the state. This is hte code:

     

    Code Snippet

    public static void MyPipeClient3 ( string msg )

    {

    for ( int jj = 0; jj < Globals.generListThreads.Count; jj++ )

    {

    if ( Globals.generListThreads[ jj ].Name == "clientPipe" )

    {

    if ( Globals.generListThreads[ jj ].IsAlive == false )

    {

    Globals.generListThreads[ jj ].Start ( );

    break;

    }

    }

    }

    if ( pipeClient2.IsConnected == false )

    {

    pipeClient2.Connect ( );

    }

    // sending messages

    UTF8Encoding encoding = new UTF8Encoding ( );

    byte[ ] bytes = encoding.GetBytes ( msg );

    pipeClient2.Write ( bytes, 0, bytes.Length );  // <== exception here.

    } // MyPipeClient3  //

     

     

     

    When I place a break point on the statement marked "<== exception here" I get this evaluation:

     

    pipeClient2.IsMessageComplete "Cannot evaluate expression because the current thread is in a sleep, wait, or join"

     

    No exception is actually "thrown" the program just hangs in there or perhaps loops somewhere I cannot find where. After pressing CTRL + ALT + Break I get it at a function and then lead it step by step to this statement.

     

    BTW the .Start ( ) statement is not really needed. The thread is connected and it is alive all the time.

     

    What does it mean? How can I get around it.

     

    Thanks.

     

     

    P.S. This editor is a big pain in the neck.

     

     

    Friday, March 14, 2008 4:16 PM

Answers

  •  Hanzheng Zou wrote:

    Hi, AlexBB.

     

    The message "Cannot evaluate expression because the current thread is in a sleep, wait, or join."  should be caused because the thread is waiting for another thread to complete a task.

     

    I agree with what Peter Ritchie wrote, it might be that the destination application is not responding.

     

    Based on my understanding,I think maybe you can add some code in the client to check about the state of the thread. Use ICorDebugThread::GetUserState() to examine your user thread state. Read the MSDN http://msdn2.microsoft.com/en-us/library/ms232109.aspx .

     

    The enumeration values indicates the different states.

    typedef enum CorDebugUserState {
        USER_STOP_REQUESTED     = 0x01,
        USER_SUSPEND_REQUESTED  = 0x02,
        USER_BACKGROUND         = 0x04,
        USER_UNSTARTED          = 0x08,
        USER_STOPPED            = 0x10,
        USER_WAIT_SLEEP_JOIN    = 0x20,
        USER_SUSPENDED          = 0x40,
        USER_UNSAFE_POINT       = 0x80,
    } CorDebugUserState;

    Then think about if the destionation application has really responesed your client's connection.

     

    Zou

     

    I appreciate you comment and the code you've prpvided. Also you focused my attention on the method I've neglected for no reason. Now I will use it all the time.

     

    I am wondering though if it would give me more than I can see in the debugger's Thread window which I invoke by CTRL + ALT + H  shortcut? It remains to be seen.

     

    Actually I resolved the whole problem:

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2994048&SiteID=1

     

    The culprit was my negligence. I set up two buttons to invoke the secondary form but put the code to invoke the threads and the pipes in one of them only. Such things do happen in debug when you do a lot of stuff temporarily and don't pay much attention to consequences. In the event I was pressing the wrong button and the client simply was NOT there for the server to respond. It is comical now to recall this all. It is just another lesson for me.

     

    The pipes are now working full steam.

     

    Thank you very much.

    Tuesday, March 18, 2008 3:57 PM

All replies

  • That may happen because the thread making the call to Write is likely in a wait state waiting for the message to be "sent".  This might occur because the destination application is not responding?

     

    I haven't had a chance yet to play with the named pipes in 3.5; so I don't know if the original example you've referenced has any inherent problems. 

     

    Friday, March 14, 2008 4:37 PM
    Moderator
  •  Peter Ritchie wrote:

    That may happen because the thread making the call to Write is likely in a wait state waiting for the message to be "sent".  This might occur because the destination application is not responding?

     

    I haven't had a chance yet to play with the named pipes in 3.5; so I don't know if the original example you've referenced has any inherent problems. 

     

     

    "This might occur because the destination application is not responding?"

     

    How can I stimulate it?

    Saturday, March 15, 2008 12:15 AM
  • Hi, AlexBB.

     

    The message "Cannot evaluate expression because the current thread is in a sleep, wait, or join."  should be caused because the thread is waiting for another thread to complete a task.

     

    I agree with what Peter Ritchie wrote, it might be that the destination application is not responding.

     

    Based on my understanding,I think maybe you can add some code in the client to check about the state of the thread. Use ICorDebugThread::GetUserState() to examine your user thread state. Read the MSDN http://msdn2.microsoft.com/en-us/library/ms232109.aspx .

     

    The enumeration values indicates the different states.

    typedef enum CorDebugUserState {
        USER_STOP_REQUESTED     = 0x01,
        USER_SUSPEND_REQUESTED  = 0x02,
        USER_BACKGROUND         = 0x04,
        USER_UNSTARTED          = 0x08,
        USER_STOPPED            = 0x10,
        USER_WAIT_SLEEP_JOIN    = 0x20,
        USER_SUSPENDED          = 0x40,
        USER_UNSAFE_POINT       = 0x80,
    } CorDebugUserState;

    Then think about if the destionation application has really responesed your client's connection.

     

     

     

    Zou

    Tuesday, March 18, 2008 8:36 AM
  •  Hanzheng Zou wrote:

    Hi, AlexBB.

     

    The message "Cannot evaluate expression because the current thread is in a sleep, wait, or join."  should be caused because the thread is waiting for another thread to complete a task.

     

    I agree with what Peter Ritchie wrote, it might be that the destination application is not responding.

     

    Based on my understanding,I think maybe you can add some code in the client to check about the state of the thread. Use ICorDebugThread::GetUserState() to examine your user thread state. Read the MSDN http://msdn2.microsoft.com/en-us/library/ms232109.aspx .

     

    The enumeration values indicates the different states.

    typedef enum CorDebugUserState {
        USER_STOP_REQUESTED     = 0x01,
        USER_SUSPEND_REQUESTED  = 0x02,
        USER_BACKGROUND         = 0x04,
        USER_UNSTARTED          = 0x08,
        USER_STOPPED            = 0x10,
        USER_WAIT_SLEEP_JOIN    = 0x20,
        USER_SUSPENDED          = 0x40,
        USER_UNSAFE_POINT       = 0x80,
    } CorDebugUserState;

    Then think about if the destionation application has really responesed your client's connection.

     

    Zou

     

    I appreciate you comment and the code you've prpvided. Also you focused my attention on the method I've neglected for no reason. Now I will use it all the time.

     

    I am wondering though if it would give me more than I can see in the debugger's Thread window which I invoke by CTRL + ALT + H  shortcut? It remains to be seen.

     

    Actually I resolved the whole problem:

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2994048&SiteID=1

     

    The culprit was my negligence. I set up two buttons to invoke the secondary form but put the code to invoke the threads and the pipes in one of them only. Such things do happen in debug when you do a lot of stuff temporarily and don't pay much attention to consequences. In the event I was pressing the wrong button and the client simply was NOT there for the server to respond. It is comical now to recall this all. It is just another lesson for me.

     

    The pipes are now working full steam.

     

    Thank you very much.

    Tuesday, March 18, 2008 3:57 PM