Exemplo n.º 1
0
        private async Task <int> Run()
        {
            var pid = Process.GetCurrentProcess().Id;

            Log.Logger.Information($"Long running process started. PID={pid}");

            var parentPid = _configRoot.GetValue <int?>("ParentProcessId");

            using (parentPid.HasValue
                ? new ProcessExitedHelper(parentPid.Value, _ => ParentExited(parentPid.Value), new NullLoggerFactory())
                : NoopDisposable.Instance)
            {
                using (await CooperativeShutdown.Listen(ExitRequested, new NullLoggerFactory()))
                {
                    // Poll the shutdown token in a tight loop
                    while (!_shutdown.IsCancellationRequested || _ignoreShutdownSignal)
                    {
                        await Task.Delay(100);
                    }
                    Log.Information("Exiting.");
                }
            }

            return(_exitWithNonZero ? -1 : 0);
        }
Exemplo n.º 2
0
        private async Task Run()
        {
            var pid = Process.GetCurrentProcess().Id;

            Log.Logger.Information($"Long running process started. PID={pid}");

            var parentPid = _configRoot.GetValue <int?>("ParentProcessId");

            using (parentPid.HasValue
                ? new ProcessExitedHelper(parentPid.Value, _ => ParentExited(parentPid.Value))
                : NoopDisposable.Instance)
            {
                using (await CooperativeShutdown.Listen(ExitRequested))
                {
                    while (!_shutdown.IsCancellationRequested)
                    {
                        await Task.Delay(100);
                    }
                    Log.Information("Exiting.");
                }
            }
        }
Exemplo n.º 3
0
        static async Task Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Console()
                         .CreateLogger();

            var pid = Process.GetCurrentProcess().Id;

            Log.Logger.Information($"Long running process started. PID={pid}");

            if (args.Contains("--debug"))
            {
                Debugger.Launch();
            }

            try
            {
                using (new ProcessMonitor(ParentExited))
                {
                    using (await CooperativeShutdown.Listen(ExitRequested))
                    {
                        var stopWatch = Stopwatch.StartNew();
                        // Yeah this process is supposed to be "non-terminating"
                        // but we don't want tons of stray instances running
                        // because of tests so it terminates after a long
                        // enough time.
                        while (stopWatch.Elapsed < TimeSpan.FromSeconds(100))
                        {
                            await Task.Delay(100);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex, ex.Message);
            }
        }