Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            using (CancellationTokenSource cts = new CancellationTokenSource())
            {
                TraceSource traceSource = new TraceSource("CleanupSample", SourceLevels.All);
                traceSource.Listeners.Add(new ConsoleTraceListener()
                {
                    TraceOutputOptions = TraceOptions.DateTime | TraceOptions.ThreadId
                });

                CleanupGuard guard = new CleanupGuard();
                Task         task  = guard.RunAsync(g => RunSampleAsync(g, traceSource, cts.Token));

                Console.WriteLine("Press ENTER to stop.");
                Console.ReadLine();

                cts.Cancel();

                try
                {
                    task.Wait();
                }
                catch (Exception e)
                {
                    traceSource.TraceEvent(TraceEventType.Error, 0, "ERROR: {0}", e);
                }
            }
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            using (CancellationTokenSource cts = new CancellationTokenSource())
            {
                TraceSource traceSource = new TraceSource("CleanupSample", SourceLevels.All);
                traceSource.Listeners.Add(new ConsoleTraceListener() { TraceOutputOptions = TraceOptions.DateTime | TraceOptions.ThreadId });

                CleanupGuard guard = new CleanupGuard();
                Task task = guard.RunAsync(g => RunSampleAsync(g, traceSource, cts.Token));

                Console.WriteLine("Press ENTER to stop.");
                Console.ReadLine();

                cts.Cancel();

                try
                {
                    task.Wait();
                }
                catch (Exception e)
                {
                    traceSource.TraceEvent(TraceEventType.Error, 0, "ERROR: {0}", e);
                }
            }
        }