R
R
Rhapsody2014-06-09 18:10:06
C++ / C#
Rhapsody, 2014-06-09 18:10:06

How to terminate a thread that is listening on a port

There is an application, on the button "Start" in a separate flow the port is listened. It is necessary to pause the flow on the "Stop" button. The problem is that while (true) is there and when the Thread.Abort () method is called, a blocking occurs. Please tell me how to solve this problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2014-06-10
@r4tz52

Why are you using Thread? Why not a BackgroundWorker with while (!worker.CancellationPending)?

S
Sumor, 2014-06-09
@Sumor

Abort does not interrupt the execution of the thread, but only tells it that someone wants to abort it.
Replace while(true) with while(Thread.CurrentThread.ThreadState & (ThreadState.AbortRequested)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question