Commit 79528dc3 authored by biasmey's avatar biasmey
Browse files

wait for a queue

parent 127733c8
......@@ -9,19 +9,28 @@ using System.Threading;
namespace NotificationWriterService
{
//to use https://nssm.cc/ to install as a service in windows
class Program
{
static CancellationTokenSource source = new CancellationTokenSource();
static CancellationToken token = source.Token;
static void Main(string[] args)
{
IServiceProvider serviceProvider = ConfigureServices();
var source = new CancellationTokenSource();
var token = source.Token;
var serviceProvider = ConfigureServices();
var fileWatchManager = serviceProvider.GetRequiredService<IFileWatchManager>();
fileWatchManager.Run(token).ConfigureAwait(false);
var t = fileWatchManager.Run(token);
Console.CancelKeyPress += (s, e) => { // https://nssm.cc/ trigger this event when the service is stoped
source.Cancel();
Log.Information("The app is shutting down.");
t.Wait();// wait for the queue is empty
};
while (!token.IsCancellationRequested);
while (!t.IsCompleted);
}
private static IServiceProvider ConfigureServices()
......@@ -59,9 +68,6 @@ namespace NotificationWriterService
}
private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
{
source.Cancel();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment