I am creating an event-driven class, so when I pass it a series of data, it will process and then return the value when ready.
Below is the code that I am using at the moment below, however it is rather nasty, and I'm not sure if it could be easier than that.
public delegate void MyEventHandler(double result);
public static MyEventHandler EventComplete;
public static void MakeSomethingHappen(double[] data)
{
ThreadPool.QueueUserWorkItem(DoSomething, data);
}
private static void DoSomething(object dblData)
{
InvokeEventComplete(AndSomethingElse((double[])dblData));
}
private static void InvokeEventComplete(double result)
{
if (EventComplete != null)
{
EventComplete(result);
}
}
public static double AndSomethingElse(double[] data)
{
return result;
}
In my main class, I just hook a method to an event like this,
MyClass.EventComplete += new MyClass.EventCompleteHandler(MyClass_EventComplete);
source
share