Why does Thread.Join() hang even though the methods in the thread have returned?

后端 未结 1 1501
轮回少年
轮回少年 2021-01-19 00:12

I have a WPF application which uses some library code for authentication which needs to run in a Single-Thread Apartment thread. My approach is to spawn a separate thread to

1条回答
  •  广开言路
    2021-01-19 00:45

    Based on your code; it looks as if you're doing it correctly, but the thread is never REALLY terminating. Try setting a breakpoint at the END of the function in the thread; instead of the return keyword (in case you're doing some kind of processing in your return statement that prevents the thread from exiting), as shown in the picture below enter image description here. Naming the thread using authenticationThread.Name (or mthread.Name as shown in example) can also aid with debugging. If the thread REALLY terminated, you should see "The thread 'yourname' (0x143c) has exited with code 0 (0x0)." in the Output window of Visual Studio.

    0 讨论(0)
提交回复
热议问题