遗失的星空

导航

【摘要】多线程 - BeginInvoke异步调用

private delegate int MyMethod();
private int method()
{
    Thread.Sleep(10000);
    return 100;
}
private void MethodCompleted(IAsyncResult asyncResult)
{
    if (asyncResult == null) return;
    textBox1.Text = (asyncResult.AsyncState as 
    MyMethod).EndInvoke(asyncResult).ToString();
}

private void button1_Click(object sender, EventArgs e)
{

    MyMethod my = method;
    IAsyncResult asyncResult = my.BeginInvoke(MethodCompleted, my);
}

摘录自

posted on 2014-12-04 11:11  遗失的星空  阅读(184)  评论(0编辑  收藏  举报