コード例 #1
0
        public static void Run(this IFullNode node, CancellationToken cancellationToken, string shutdownMessage)
        {
            using (node)
            {
                node.Start();

                if (!string.IsNullOrEmpty(shutdownMessage))
                {
                    Console.WriteLine();
                    Console.WriteLine(shutdownMessage);
                    Console.WriteLine();
                }

                cancellationToken.Register(state =>
                {
                    ((INodeLifetime)state).StopApplication();
                },
                                           node.NodeLifetime);

                var waitForStop = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);
                node.NodeLifetime.ApplicationStopping.Register(obj =>
                {
                    var tcs = (TaskCompletionSource <object>)obj;
                    tcs.TrySetResult(null);
                }, waitForStop);

                //await waitForStop.Task;
                waitForStop.Task.GetAwaiter().GetResult();

                node.Stop();
            }
        }