Question

I have a piece of code where I send a file content over tcp/ip channel. There are times when this connection hangs causing entire application to freeze. Is there a way for my main thread to spawn a worker thread and monitor that worker thread. If worker thread succeeds, well and good. If it hangs , the main thread could log error message and continue. How can I simulate in my test code that a worker thread is hanging. please let me know what could the code look like. I am using C# Visual studio 2002.

Was it helpful?

Solution

Surely this is possible.

Either you implement threading manually using the BackgroudWorker or Thread class or (in your case even simpler) you use the asynchroneous methods for sending your content.

All the network related classes contain asynchroneous methods for their operations. Look for the methods that contain Async or Begin...

And simulating a dead thread is simple. Just make an endless loop:

while (true)
     System.Threading.Thread.Sleep (10);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top