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.
Asked
Active
Viewed 119 times
1

Dariusz Woźniak
- 9,640
- 6
- 60
- 73

dotnet-practitioner
- 13,968
- 36
- 127
- 200
-
@Aren B: That would be Visual Studio .NET, using .NET 1.0. The version Microsoft tries to pretend doesn't exist. – Powerlord Jun 02 '10 at 16:57
-
@R. Bemrose: Precursor to 2003 for 1.1 i guess? – Aren Jun 02 '10 at 17:46
1 Answers
3
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);

Foxfire
- 5,675
- 21
- 29
-
Nobody could give you a code example until you show what you've got currently because there are several classes which you could use. In the most simple case (e.g. Using WebClient you would register the OnDownloadDataCompleted and possibly OnDownloadProgressChanged event and then call webClient.DownloadDataAsync (uri). – Foxfire Jun 02 '10 at 16:46