I am trying to create a form that will animate something while processing a specific task (passed as a delegate to the constructor). It works fine, but the problem is that I cannot create an instance of my generic class if the specific method that I want to execute has a return type of void.
I understand that this is by design and all, but I wonder if there is a well-known workaround for such situations.
If this helps, then my window shape looks like this (cropped for brevity):
public partial class operatingWindow<T> : Form
{
public delegate T Operation();
private Operation m_Operation;
private T m_ReturnValue;
public T ValueReturned { get { return m_ReturnValue; } }
public operatingWindow(Operation operation) { }
}
And I call it that:
operatingWindow<int> processing = new operatingWindow<int>(new operatingWindow<int>.Operation(this.doStuff));
processing.ShowDialog();
private int doStuff()
{
Thread.Sleep(3000);
return 0;
}
source
share