工作流未正确执行,但不会引发异常

时间:2012-02-29 00:19:14

标签: workflow-foundation-4

我正在使用Microsoft wf示例项目:WF_WCF_Samples \ WF \ Application \ VisualWorkflowTracking \ CS 此示例项目运行wf4模拟。

工作流有一个输入bool参数。

目前我有两个问题。

第一个问题:

如果我在参数(工作流设计器)中输入一个值,那么当代码运行但模拟没有执行时,我不会得到任何异常。

我修改了代码并尝试获取参数集合。然后我将它们添加到Dictionary中,然后将其传递给Invoke方法。这种方法不会给我带来任何错误,但它不会启动该过程。我认为参数的值没有被正确地传递给Dictionary。以下是代码:

ThreadPool.QueueUserWorkItem(new WaitCallback((context) =>
{

    bool noArguments = false;

    var serviceManager = this.WorkflowDesigner.Context.Services;

    Dictionary<string, object> retval = new Dictionary<string, object>();
    var modelService = serviceManager.GetService<ModelService>();
    var rootModelItem = modelService.Root;

    var properties = rootModelItem.Properties["Properties"];
    if (properties == null) noArguments = true;

    var propertiesCollection = properties.Collection;
    if (propertiesCollection == null) noArguments = true;
    if (propertiesCollection.Count == 0) noArguments = true;

    foreach (var p in propertiesCollection)
    {
        var d = p.GetCurrentValue() as DynamicActivityProperty;
        if (d != null)
        {
            var name = d.Name;
            dynamic inArgument = d.Value;

            try
            {
                var val = inArgument.Expression.Value;
                retval.Add(name, val);
            }
            catch (Exception er)
            {
                MessageBox.Show("Variable: " + d.Name + " Value is Empty", "Variable Error",MessageBoxButton.OK,MessageBoxImage.Error);
            }
        }

    }

    //Invoking the Workflow Instance with Input Arguments
    if (noArguments)
    {
        instance.Invoke();
    }
    else
    {
        //this line below does raise any error but it does not run the process.
        //instance.Invoke(retval, new TimeSpan(1, 0, 0));  

//this line below works as long as in the workflow designer the argument value is left blank
        instance.Invoke(new Dictionary<string, object> { { "decisionVar", "hello" } }, new TimeSpan(1, 0, 0));
    }


    //This is to remove the final debug adornment
    this.Dispatcher.Invoke(DispatcherPriority.Render
        , (Action)(() =>
    {
        this.WorkflowDesigner.DebugManagerView.CurrentLocation = new SourceLocation(this.WorkFlowFile,1,1,1,10);
        //this.WorkflowDesigner.DebugManagerView.CurrentLocation = new SourceLocation("Workflow.xaml",1,1,1,10);
    }));

}));

1 个答案:

答案 0 :(得分:1)

可能是抛出异常并终止正在执行工作的线程。您可能希望使用try / catch块包围整个事件并记录异常。