I have a bug in my application that seems to show its face only when I pause the application in the debugger for several minutes. I suspect this is due to a third-party network library that I'm using, with a heartbeat thread that disconnects when it cannot ping the server while the interrupt thread is interrupted.
I am trying to write a testing application to make sure that this is the cause of the error. To do this, I need a way to pause all threads in the application (which I judge later, to pause only the thread, which I suspect might be a heartbeat thread) to simulate pausing the application in the debugger.
Does anyone know how to do this? Is it possible for one thread to make another sleep?
Thanks Alex
UPDATE:
In the end, I decided that I really did not need the application to do this for me, because I just had to check that the suspension in the debugger caused a break. So, here's what I did ... (The simplest ways are often the best ... or at least the simplest ...)
private static void Main(string[] args) { IPubSubAdapter adapter = BuildAdapter(); bool waitingForMessage; adapter.Subscribe(_topic, message => waitingForMessage = false, DestinationType.Topic); Stopwatch timePaused = new Stopwatch(); while (adapter.IsConnected) { Console.WriteLine("Adapter is still connected"); waitingForMessage = true; adapter.Publish(_topic, "testmessage", DestinationType.Topic); while (waitingForMessage) { Thread.Sleep(100); } timePaused.Reset(); timePaused.Start(); Debugger.Break(); timePaused.Stop(); Console.WriteLine("Paused for " + timePaused.ElapsedMilliseconds + "ms."); Thread.Sleep(5000);
And the conclusion:
Adapter is still connected Paused for 10725ms. Adapter is still connected Paused for 13298ms. Adapter is still connected Paused for 32005ms. Adapter is still connected Paused for 59268ms. Adapter is disconnected!
AlexC
source share