Menu

multiple user control task initialization

Help
2009-06-16
2013-04-26
  • Ediber Montoya Moreira

    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?

     
    • OVZH

      OVZH - 2009-06-21

      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

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.