A simple class for creating a log viewer. Call the static Log message.
        public static Task<LogViewer> CreateLogViewer()
        {
            var tcs = new TaskCompletionSource<LogViewer>();
            var thread = new Thread(() =>
            {
                // Set up the SynchronizationContext so that any awaits
                // resume on the STA thread as they would in a GUI app.
                SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext());
                var viewer = new LogViewer();
                viewer.Show();
                tcs.SetResult(viewer);
                Dispatcher.Run();
            });
            thread.Name = "LoggerThread";

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            return tcs.Task;
        }
Exemple #2
0
        public static Task <LogViewer> CreateLogViewer()
        {
            var tcs    = new TaskCompletionSource <LogViewer>();
            var thread = new Thread(() =>
            {
                // Set up the SynchronizationContext so that any awaits
                // resume on the STA thread as they would in a GUI app.
                SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext());
                var viewer = new LogViewer();
                viewer.Show();
                tcs.SetResult(viewer);
                Dispatcher.Run();
            });

            thread.Name = "LoggerThread";

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            return(tcs.Task);
        }