I'm trying to create a reusable user control that fires a custom task to select values. The problem is that I need to get the results back from the selecting task. The mechanism to pass information between tasks is the method “OnStart”, so, in order to be independent from the containing Form I need to get a task instance associated to the controller of the user control. Also I need more than one instances of the user control in the same form. Is there a way to do it?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
class MyTask : TaskBase
...
public IMyTaskResultListener MyTaskResultListener;
public override void OnStart(object param)
{
MyTaskResultListener = param as IMyTaskResultListener;
}
class MyTaskController : ControllerBase<MyTask, IMyView>
...
public void FinishWork()
{
object[] result = new object[] {1, 2, 3};
Task.MyTaskResultListener.RecieveMyTaskResult(result);
}
Some other variations are possible as well. For example you may use an event in the MyTask class. The UserControlController.StartMyTask should then subscribe to this event.
To use several user control views of the same type just assign different ViewName property values to them.
Regards,
--
Oleg Zhukov
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to create a reusable user control that fires a custom task to select values. The problem is that I need to get the results back from the selecting task. The mechanism to pass information between tasks is the method “OnStart”, so, in order to be independent from the containing Form I need to get a task instance associated to the controller of the user control. Also I need more than one instances of the user control in the same form. Is there a way to do it?
Hi,
You may pass the controller itself as the task parameter:
class UserControlController : ControllerBase, IMyTaskResultListener
...
public void StartMyTask()
{
Task.TasksManager.StartTask(typeof(MyTask), this);
}
public void RecieveMyTaskResult(object[] values)
{
// do something with values
}
...
interface IMyTaskResultListener
{
void RecieveMyTaskResult(object[] values);
}
class MyTask : TaskBase
...
public IMyTaskResultListener MyTaskResultListener;
public override void OnStart(object param)
{
MyTaskResultListener = param as IMyTaskResultListener;
}
class MyTaskController : ControllerBase<MyTask, IMyView>
...
public void FinishWork()
{
object[] result = new object[] {1, 2, 3};
Task.MyTaskResultListener.RecieveMyTaskResult(result);
}
Some other variations are possible as well. For example you may use an event in the MyTask class. The UserControlController.StartMyTask should then subscribe to this event.
To use several user control views of the same type just assign different ViewName property values to them.
Regards,
--
Oleg Zhukov