I wrote a test program to help understand asynchronous calls in c#. I
have a working VB.NET app that uses a similar technique but I cannot
get it to work in c#. The errors I get and the code below. I
understand the need for threading when updating UI and the general
concept of what is going on but do not understand the two errors.:
Error 1 'testwinform.Fo rm1.WorkDoneDel egate()' must declare a body
because it is not marked abstract or extern C:\Development\ testwinform
\testwinform\Fo rm1.cs 20 26 testwinform
Error 2 'testwinform.Wo rker.AsyncMetho dCaller()' must declare a body
because it is not marked abstract or extern C:\Development\ testwinform
\testwinform\Wo rker.cs 21 26 testwinform
using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;
using System.Threadin g;
namespace testwinform
{
public partial class Form1 : Form
{
public Form1()
{
InitializeCompo nent();
}
public Delegate WorkDoneDelegat e();
private void btnStart_Click( object sender, EventArgs e)
{
Worker ad = new Worker();
AsyncMethodCall er caller = new
AsyncMethodCall er(ad.WorkerThr ead);
IAsyncResult result = caller.BeginInv oke(CallBackMet hod);
}
private void CallBackMethod( IAsyncResult result)
{
AsyncMethodCall er caller =
AsyncMethodCall er(result.Async State);
string returnvalue = caller.EndInvok e(result);
if (this.lblMessag e.InvokeRequire d)
{
WorkDoneDelegat e wd = new
WorkDoneDelegat e(CallBackMetho d);
this.Invoke(wd, new object()(return value));
}
else
lblMessage.Text = "Done";
}
}
}
//here is the class with the worker thread
using System;
using System.Collecti ons.Generic;
using System.Text;
namespace testwinform
{
class Worker
{
public Worker()
{
}
public string WorkerThread()
{
Thread.Sleep(10 );
return ("Done");
}
//delegate used in asynchronous callback
public Delegate AsyncMethodCall er();
}
}