麦田

不积跬步无以至千里.

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
 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();

                }

                }));

 

posted on 2012-12-20 15:13  一些记录  阅读(858)  评论(0)    收藏  举报