locked
Catch exception from different thread RRS feed

  • Question

  • I have a workflow that exchanges data with a WinForms GUI. On the GUI thread an exception is raised while a workflow activity is being executed. The code to exectue the activity is:

     

    protected sealed override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

    {

    try

    {

    ExecuteActivity(executionContext);

    }

    catch

    {

    ....

    }

    }

     

    The problem is, the exception raised on the GUI is not caught by this try-catch-block. Obviously, that's because the exception is raised on a different thread (the GUI thread), but the exception handler is on the workflow thread. My question is, is it somehow possible to delegate the raising of the exception to the workflow thread, so that this handler can catch it? With other words, I am trying to do something like (pseudo code):

     

    // called on the GUI thread

    Invoke(new MyDelegate(OnThrowException));

     

    // exectued on the workflow thread such that the handler above can catch this exception

    void OnThrowException()

    {

    throw new ArgumentException();

    }

     

    Thanks in advance.

    Monday, November 17, 2008 11:45 AM