I am writing a socket server and client classes, which I'm testing through NUnit.
I wrote a process, which is checking all clients, if they are still connected. For this process I created a Thread, but what I want is to run this check only like every 5 seconds. My first intension was to use Thread.Sleep()
. When I am ending the test, I am running the Stop method on server, which interrupt all active threads, which is causing that Thread
was interruted from a waiting state.
I find out there is alternative through the Task.Delay().Wait()
, but this is causing the same problem.
Is there any other alternative to Thread.Sleep
, or any other way, when I am closing server to end this thread? The thread is running while loop with condition Thread.CurrentThread.IsAlive
.