110,534
社区成员
发帖
与我相关
我的任务
分享
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public delegate void FunDelegate();
public delegate void SetValue(int i);
private void button1_Click(object sender, EventArgs e)
{
FunDelegate fundelegate = new FunDelegate(FunProc);
AsyncCallback callback = new AsyncCallback(CallBack);
IAsyncResult result = fundelegate.BeginInvoke(callback, "处理结束");
}
public void CallBack(IAsyncResult result)
{
MessageBox.Show(result.AsyncState.ToString());
}
public void SetListBox(int i)
{
if (this != null && !this.IsDisposed)
{
if (this.InvokeRequired)
{
this.Invoke(new SetValue(SetListBox), i);
}
else
{
listBox1.Items.Add(i);
}
}
}
public void FunProc()
{
for (int i = 0; i < 5000; i++)
{
Thread.Sleep(100);
SetListBox(i);
}
}
}
System.Environment.Exit(-1);