日期:2014-05-17 浏览次数:21026 次
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;
namespace ASY
{
public partial class Form1 : Form
{
public delegate string delegateInvoke(string parm);
public delegate string delegateAppendText(string msg);
public Form1()
{
InitializeComponent();
}
public string InvokedMethod(string parm)
{
delegateAppendText da = new delegateAppendText(InvokedMethod);
if (textBox1.InvokeRequired)
{
textBox1.Invoke(da, parm);
}
else
{
textBox1.Text = parm;
}
return "Asy called," + parm ;
}
private void button1_Click(object sender, EventArgs e)
{
delegateInvoke delegateinvoke = new delegateInvoke(InvokedMethod);
delegateinvoke.BeginInvoke("ok", new AsyncCallback(callComplete), null);
}
private void callComplete(IAsyncResult ir)
{
delegateInvoke di = (delegateInvoke)ir.AsyncState;
di.EndInvoke(ir);
}
}
}