基本信息
源码名称:实现winFrom加载效果
源码大小:0.26M
文件格式:.zip
开发语言:C#
更新时间:2017-11-18
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
多线程执行耗时操作,为了用户体验,显示正在加载效果。


namespace WindowsFormsApplication16
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            WaitFormService.Cancle = WaitFormService_Cancle;
        }

        private bool WaitFormService_Cancle()
        {
            return isUserCancle;
        }

        private void ExecWaitForm()
        {
            try
            {
                WaitFormService.Show();
            }
            catch (Exception ex)
            {
                // WaitFormService.Close();
            }
        }
        Thread th;
        private void button1_Click(object sender, EventArgs e)
        {
            //bool noRun = false;
            //System.Threading.Mutex Run = new System.Threading.Mutex(true, "ThreadExecWaitForm", out noRun);
            //if (noRun)//没有
            //{
                th = new Thread(new ThreadStart(ExecWaitForm));
                th.IsBackground = true;
                th.Name = "ThreadExecWaitForm";
                th.Start();
            //}
            //else //有
            //{
            //    MessageBox.Show("有在运行");
            //}
         
        }
        private bool isUserCancle = false;
        private void btnClose_Click(object sender, EventArgs e)
        {
            
            try
            {
                isUserCancle = true;
                th.Abort();
                WaitFormService.Close();
                isUserCancle = false;
            }
            catch
            {

            }

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            isUserCancle = true;
            WaitFormService.Close();
            isUserCancle = false;
        }

        private void btnLongWork_Click(object sender, EventArgs e)
        {
          
            th = new Thread(new ThreadStart(ExecWaitForm));
            th.IsBackground = true;
            th.Start();
        }
    }
}