V
V
Vinni372018-09-21 15:32:32
C++ / C#
Vinni37, 2018-09-21 15:32:32

C# Watchdog for thread?

A MITM proxy server is being written using NetworkStream and SslStream.
The problem is that NetworkStream doesn't signal connection close (callback or exception).
For example, a request "proxy server" has been processed and is waiting for the Web server to respond ( NetworkStream.Read ), or it's set to Connection: keep-alive and you need to keep the connection, or the situation when the channel is slow and receiving data takes a long time, in general, it doesn't matter if it takes a long time work as a Web server via NetworkStream/SslStream. And the client NetworkStream closed (timeout or browser tab closed).
I see an option, when processing a new client NetworkStream, to start monitoring it in a separate thread for an exception with a zero write to the stream (as recommended by MSDN).
From here the question is how to complete the parent thread from the child thread.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
basrach, 2018-09-22
@basrach

how to terminate parent thread from child thread.

Threads do not have a parent/child relationship. End accordingly as always:
var parentThread = new Thread(..
...
parentThread.Abort();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question