在我们的自定义活动中以编程方式引发Fault事件 [英] Programmatically raised Fault event in our custom activity

查看:56
本文介绍了在我们的自定义活动中以编程方式引发Fault事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

正如标题所示,如何在我们的自定义活动(从NativeActivity继承)中以编程方式引发Fault事件,以便在安排自定义活动之后调用OnFaulted事件处理程序?

代码段:

    protected override void Execute(System.Activities.NativeActivityContext context)
    {
      ActivityInstance ai = null;
      String text = Text.Get(context);

      context.SetValue(_text, text);

//how to make this line raise Fault event so that OnFaulted event handler is invoked
      ai = context.ScheduleActivity(_writeLine, OnComplete, OnFaulted);

    }

    private void OnComplete(NativeActivityContext context, ActivityInstance completedInstance)
    {
      Result.Set(context, new PrintCommandResult());
      Console.WriteLine("OnComplete: Activity Id: {0}", completedInstance.Id);
    }

    private void OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
    {
      Console.WriteLine("OnFaulted: {0}, from activity Id: {1}", propagatedException.Message, propagatedFrom.Id);
    }

解决方案

Arinto

您可以尝试除以零".犯错了

问候


Hi all, 

As the title suggests, how can we programmatically raise Fault event in our custom activity (inherits from NativeActivity) so that OnFaulted event handler is invoked after we schedule our custom activity? 

Code snippets:

    protected override void Execute(System.Activities.NativeActivityContext context)
    {
      ActivityInstance ai = null;
      String text = Text.Get(context);

      context.SetValue(_text, text);

//how to make this line raise Fault event so that OnFaulted event handler is invoked
      ai = context.ScheduleActivity(_writeLine, OnComplete, OnFaulted);

    }

    private void OnComplete(NativeActivityContext context, ActivityInstance completedInstance)
    {
      Result.Set(context, new PrintCommandResult());
      Console.WriteLine("OnComplete: Activity Id: {0}", completedInstance.Id);
    }

    private void OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
    {
      Console.WriteLine("OnFaulted: {0}, from activity Id: {1}", propagatedException.Message, propagatedFrom.Id);
    }

解决方案

Hi, arinto

You can try "dividen by zero" to make a fault.

Regards


这篇关于在我们的自定义活动中以编程方式引发Fault事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆