none
invoke a delegate inside thread/task. RRS feed

  • Question

  • Hello. I have a task which is running constantly and i need to invoke a delegate in the context of that task. How can i do it?
    Wednesday, June 25, 2014 12:34 PM

Answers

  • Hi Booster,

    I assume you want to log app running state from a long-running task. Please refer to the following link for details. http://stackoverflow.com/questions/3793105/threads-and-delegates-i-dont-fully-understand-their-relations.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, June 26, 2014 6:59 AM
    Moderator
  • I don't understand this but it's definitely not what i need. Imagine we have a running thread or task and we need to execute a delegate in the context of it. By the way i've solved  this problem through adding dispatcher into thread. I just call function DoEvents inside thread loop.

     private static void DoEvents()
     {
           var frame = new DispatcherFrame();
           Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrame), frame);
           Dispatcher.PushFrame(frame);
     }
    
    private static object ExitFrame(object dispatcherFrame)
    {
         ((DispatcherFrame)dispatcherFrame).Continue = false;
         return null;
    }

    Thursday, June 26, 2014 10:54 AM

All replies

  • Hi Booster,

    I assume you want to log app running state from a long-running task. Please refer to the following link for details. http://stackoverflow.com/questions/3793105/threads-and-delegates-i-dont-fully-understand-their-relations.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, June 26, 2014 6:59 AM
    Moderator
  • I don't understand this but it's definitely not what i need. Imagine we have a running thread or task and we need to execute a delegate in the context of it. By the way i've solved  this problem through adding dispatcher into thread. I just call function DoEvents inside thread loop.

     private static void DoEvents()
     {
           var frame = new DispatcherFrame();
           Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrame), frame);
           Dispatcher.PushFrame(frame);
     }
    
    private static object ExitFrame(object dispatcherFrame)
    {
         ((DispatcherFrame)dispatcherFrame).Continue = false;
         return null;
    }

    Thursday, June 26, 2014 10:54 AM