Beispiel #1
0
        async Task RunAndWait(Settings settings)
        {
            using (var service = new Host(true)
            {
                Settings = settings,
                ServiceName = settings.ServiceName,
            })
            {
                var tcs = new TaskCompletionSource <bool>();

                Action done = () =>
                {
                    service.OnStopping = () => { };
                    tcs.SetResult(true);
                };

                service.OnStopping = done;

                OnConsoleCancel.Run(done);

                service.Run();

                Console.WriteLine("Press Ctrl+C to exit");

                await tcs.Task.ConfigureAwait(false);
            }
        }
Beispiel #2
0
            public static void Run(Action action)
            {
                var onCancelAction = new OnConsoleCancel(action);

                Console.CancelKeyPress += onCancelAction.ConsoleOnCancelKeyPress;
            }