What do you want to do, I don't know, but you can call a delegate method asynchronously from the button event. So you can do more than one operation. For example;
private delegate string LongTaskWorkHandler(string value1, string value2);
private void button1_click(object sender, EventArgs e)
{
LongTaskWorkHandler longTaskDelegate = DoLongTask;
IAsyncResult ar = longTaskDelegate.BeginInvoke("THE", "CODEPROJECT", null, null);
while(true)
{
Console.Write(".");
if(ar.AsyncWaitHandle.WaitOne(50, false))
{
Console.WriteLine("Can get the result now.");
break;
}
}
string result = longTaskDelegate.EndInvoke(ar);
MessageBox.Show(result);
}
private string DoLongTask(string value1, string value2)
{
string output = null;
try
{
output = LongTask(value1, value2);
}
catch (Exception ex)
{
output = ex.Message;
}
return output;
}
private string LongTask(string value1, string value2)
{
Console.WriteLine("LongTask started.");
Thread.Sleep(5000);
Console.WriteLine("LongTask completed.");
return String.Format("{0} {1}", value1, value2);
}