private delegate void CrossThreadOperationControl();


           // 将代理实例化为一个匿名代理 

            CrossThreadOperationControl CrossDelete = delegate()

            {

                MessageBoxButtons buttons = MessageBoxButtons.OKCancel;

                DialogResult dr = MessageBox.Show("Master,please to have a rest!", "Interrupt", buttons);

                if (dr == DialogResult.OK)

                {

                    BlockInput(true);

                    SendMessage(this.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2);

                    myTimere.Stop();

                    System.Threading.Thread.Sleep(mySpantime);

                    myTimere.Start();

                    BlockInput(false);

                }

                else

                {

                    myWatch.Stop();

                    MessageBox.Show("Time setting be cancled!");

                    Application.Exit();

                }

            };

            this.Invoke(CrossDelete);

方法2


        this.Invoke(new MethodInvoker(delegate()

                {

                MessageBoxButtons buttons = MessageBoxButtons.OKCancel;

                DialogResult dr = MessageBox.Show("Master,please to have a rest!", "Interrupt", buttons);

                if (dr == DialogResult.OK)

                {

                    BlockInput(true);

                    SendMessage(this.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2);

                    myTimere.Stop();

                    System.Threading.Thread.Sleep(mySpantime);

                    myTimere.Start();

                    BlockInput(false);

                }

                else

                {

                    myWatch.Stop();

                    MessageBox.Show("Time setting be cancled!");

                    Application.Exit();

                }

                }));

 

相关文章:

  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
  • 2021-10-25
猜你喜欢
  • 2021-11-13
  • 2023-03-31
  • 2022-01-24
  • 2021-09-09
  • 2022-12-23
相关资源
相似解决方案