zoukankan      html  css  js  c++  java
  • 利用委托的BeginInvoke防止界面假死的实例

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;
    namespace WinBeginInvoke
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private delegate int Mydelegate();
            private int Method()
            {
                Thread.Sleep(10000);
                Random rad = new Random();
                int i = rad.Next(1000);
                return i;
            }

            private void MyMethodComplete(IAsyncResult asyncresult)
            {
                if (asyncresult == null)
                    return;
                textBox1.Text = (asyncresult.AsyncState as Mydelegate).EndInvoke(asyncresult).ToString() ;
                button1.Enabled = true;
             
            }
            private void button1_Click(object sender, EventArgs e)
            {
                Mydelegate my = Method;
                button1.Enabled = false;
                IAsyncResult result= my.BeginInvoke(MyMethodComplete, my);
                if (!result.IsCompleted)
                {
               
               
                }
               
            }
        }
    }

  • 相关阅读:
    Git工作原理
    将博客搬至CSDN
    Hive常见文件存储格式
    Hadoop进入安全模式源码分析
    Hadoop RPC简介
    hive自定义UDF函数
    hive性能调优之表设计层面调优
    flowable 启用慢 且启动不起来 报错看不懂
    数据结构和算法基础
    css: 边宽弧度
  • 原文地址:https://www.cnblogs.com/lijinchang/p/2035464.html
Copyright © 2011-2022 走看看