コード例 #1
0
        public static TraceView Create(Form parent)
        {
            TraceView view = null;

            // create it on the parent window's thread
            parent.Invoke(new Action(() => {
                view = new TraceView(parent);
                view.Show(parent);
            }));
            return(view);
        }
コード例 #2
0
        public static TraceView CreateOnOwnThread()
        {
            TraceView view = null;

            using (var sync = new ManualResetEventSlim())
            {
                // create it on its own thread
                var thread = new Thread(() =>
                {
                    SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext());
                    view = new TraceView(null);
                    view.Show();
                    sync.Set();            // ready Write calls
                    Application.Run(view); // view does Application.ExitThread() when closed
                    return;
                });

                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
                sync.Wait();
            }
            return(view);
        }