1

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.

mybrave
  • 1,662
  • 3
  • 20
  • 37
Zechy
  • 45
  • 12

1 Answers1

0

As answered in my other question, I found a better solution, because I want run the check only in periods of time (like 5 seconds or so), the good usage here is System.Threading.Timer class, which is suitable for the periodacal run of methods.

Zechy
  • 45
  • 12