private void button4_Click(object sender, EventArgs e)
{
int marktime = 0;
MyMethod my = method;
IAsyncResult asyncResult = my.BeginInvoke(MethodCompleted, my);
while (!asyncResult.IsCompleted && marktime < 4)
{
marktime += 1;
MessageBox.Show("还没完成?那我先sleep" + marktime);
Thread.Sleep(4000);
}
}
private delegate int MyMethod();
private int method()
{
Thread.Sleep(3000);
return 100;
}
private void MethodCompleted(IAsyncResult asyncResult)
{
if (asyncResult == null) return;
textBox1.Text = (asyncResult.AsyncState as MyMethod).EndInvoke(asyncResult).ToString();
//MessageBox.Show((asyncResult.AsyncState as MyMethod).EndInvoke(asyncResult).ToString());
}