示例#1
0
        private static int MainWithProgress(string args)
        {
            string currentDirectory = Path.GetDirectoryName(typeof(Maml).Module.FullyQualifiedName);

            ConsoleEnvironment env = CreateEnvironment();

#pragma warning disable CS0618 // This is the command line project, so the usage here is OK.
            using (AssemblyLoadingUtils.CreateAssemblyRegistrar(env, currentDirectory))
                                                                                         #pragma warning restore CS0618
                using (var progressCancel = new CancellationTokenSource())
                {
                    var progressTrackerTask = Task.Run(() => TrackProgress(env, progressCancel.Token));
                    try
                    {
                        return(MainCore(env, args, ShouldAlwaysPrintStacktrace()));
                    }
                    finally
                    {
                        progressCancel.Cancel();
                        progressTrackerTask.Wait();
                        // If the run completed so quickly that the progress task was cancelled before it even got a chance to start,
                        // we need to gather the checkpoints.
                        env.PrintProgress();
                    }
                }
        }
示例#2
0
 private static void TrackProgress(ConsoleEnvironment env, CancellationToken ct)
 {
     try
     {
         while (!ct.IsCancellationRequested)
         {
             // Print a dot every 0.6s, which will make 50 dots take 30 seconds.
             // REVIEW: maybe an adaptive interval that would expand if nothing happens is a better idea.
             TimeSpan interval = TimeSpan.FromSeconds(0.6);
             if (ct.WaitHandle.WaitOne(interval))
             {
                 // Cancellation was requested.
                 return;
             }
             env.PrintProgress();
         }
     }
     catch (Exception ex)
     {
         Console.Error.WriteLine("Progress tracking terminated with an exception");
         PrintExceptionData(Console.Error, ex, false);
         Console.Error.WriteLine("Progress tracking is terminated.");
     }
 }