您的位置:首页 > 编程语言 > C#

利用多线程句柄设置鼠标忙碌状态的实现方法

2013-08-19 09:23 489 查看
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Threading;

namespace CursorThread{    public partial class Form1 : Form    {        public delegate int DoSomethingDelegate(int data);

        public Form1()        {            InitializeComponent();        }

        static int DoSomething(int data)        {            /// <sumary>            /// Do something in this method            /// </sumary>            Thread.Sleep(300);            return data++;        }

        private void button1_Click(object sender, EventArgs e)        {            this.Cursor = Cursors.Default;

            DoSomethingDelegate d = DoSomething;            IAsyncResult ar = d.BeginInvoke(100,null, null);

            while (true)            {                this.Cursor = Cursors.WaitCursor;                if(ar.AsyncWaitHandle.WaitOne(50, false))                {                    this.Cursor = Cursors.Arrow;                    break;                }            }

            //Get the result            int result = d.EndInvoke(ar);            MessageBox.Show(result.ToString());

        }    }}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐