开发者

Visual Studio 2002: C# freezes when sending file over TCP/IP

开发者 https://www.devze.com 2023-01-02 14:07 出处:网络
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 wo

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.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消