Esempio n. 1
0
        public SecondWindowsThread(Action action)
        {
            ManualResetEvent mre = new ManualResetEvent(false);

            try
            {
                Thread thread = new Thread(
                    () =>
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    this.ctx = new WindowsFormsSynchronizationContext();
                    SynchronizationContext.SetSynchronizationContext(this.ctx);
                    mre.Set();
                    Application.Run();
                }
                    );
                thread.IsBackground = true;
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
                mre.WaitOne();

                this.ctx.Send(
                    (o) =>
                {
                    this.testWindow = new MyNativeWindow(action);
                    this.testWindow.CreateWindow();
                },
                    null);
            }
            finally
            {
                mre.Dispose();
            }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            UWM_HELLO = RegisterWindowMessage("TEST MESSAGE");

            this.nativeWindow = new MyNativeWindow(
                () =>
            {
                WriteHelloNW();
            }
                );
            this.nativeWindow.CreateWindow();

            this.secondWindowsThread = new SecondWindowsThread(
                () =>
            {
                Action action = this.WriteHelloFromSTA;
                this.BeginInvoke(action);
            });
        }