I have a windows service that uses Thread and SemaphoreSlim to do some βworkβ every 60 seconds.
class Daemon { private SemaphoreSlim _semaphore; private Thread _thread; public void Stop() { _semaphore.Release(); _thread.Join(); } public void Start() { _semaphore = new SemaphoreSlim(0); _thread = new Thread(DoWork); _thread.Start(); } private void DoWork() { while (true) {
I would call an asynchronous method from DoWork . To use the await keyword, I have to add async to DoWork :
private async void DoWork()
- Is there any reason not to do this?
- Can DoWork really work asynchronously if it is already running inside a dedicated thread?
source share