WF 4.0 Beta 2中的错误 [英] Error in WF 4.0 Beta 2

查看:63
本文介绍了WF 4.0 Beta 2中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!

我想我在WF 4.0 Beta 2中发现了一个错误.为了记录该错误,我对Persistence示例进行了很少的修改:
*)包装主体处于for循环中,因此将创建并运行许多WorkflowApplication实例.
*)将readline转换为计数器,以便它可以按自己的速度运行.

当我运行时在多次迭代之后,此程序总是会收到异常.例如,可能在90,000次迭代之后.程序运行始终会导致异常.

我显然希望微软的某个人想尝试一下此代码,并告诉我的代码出了什么问题,即基本上是在持久性示例,或者WF 4.0 Beta 2中确实存在错误,并且在下一版中将予以纠正.显然,所使用的数据库是根据Beta 2的说明创建的.

这是Program.cs文件的全部内容:

Hello!

I think I've found an error in WF 4.0 Beta 2. In order to document the error I've modified the Persistence sample very little:
*) Wrapped the body in a for loop so a lot of WorkflowApplication instances will be made and run.
*) Turn readline into a counter, so it may operate at its own pace.

When I run this program I always receive an exception after a number of iterations. It may for instance be after 90,000 iterations. A running of the program always results in exceptions. The exceptions do not occur after the same number of iterations at each run.

I obviously hope that somebody at Microsoft would like to try this code and either tell what is wrong in my code, i.e. basically in the Persistence sample, or that there indeed is an error in WF 4.0 Beta 2 and if it'll be corrected in the next drop. The database in use is obviously made according to the directions for Beta 2.

This is the entire contents of the Program.cs file:

//----------------------------------------------------------------

// Copyright (c) Microsoft Corporation.  All rights reserved.

//----------------------------------------------------------------



namespace Microsoft.Samples.Activities

{

    using System;

    using System.Activities;

    using System.Activities.DurableInstancing;

    using System.Activities.Statements;

    using System.Runtime.Persistence;

    using System.Threading;

    using System.Collections.Generic;

    using System.Configuration;



    class Program

    {

        static InstanceStore instanceStore;

        static AutoResetEvent instanceUnloaded = new AutoResetEvent(false);

        //static Activity activity = CreateWorkflow();

        static Guid id;



        const string readLineBookmark = "ReadLine1";



        static void SetInfo(string info)

        {

            Console.WriteLine(info);

        }



        static void Main()

        {

            SetupInstanceStore();



            for (int i = 0; i < 1000000; i++)

            {

                StartAndUnloadInstance();

                LoadAndCompleteInstance();

            }



            Console.WriteLine("Press [Enter] to exit.");

            Console.ReadLine();

        }



        static void StartAndUnloadInstance()

        {

            Activity activity = CreateWorkflow();

            WorkflowApplication application = new WorkflowApplication(activity);



            application.InstanceStore = instanceStore;



            //returning IdleAction.Unload instructs the WorkflowApplication to persists application state and remove it from memory  

            application.PersistableIdle = (e) =>

                {

                    return PersistableIdleAction.Unload;

                };



            application.Unloaded = (e) =>

                {

                    instanceUnloaded.Set();

                };





            //This call is not required 

            //Calling persist here captures the application durably before it has been started

            application.Persist();

            id = application.Id;

            application.Run();



            instanceUnloaded.WaitOne();

        }



        static long currentOrdinalValue = 0;



        static void LoadAndCompleteInstance()

        {

            //string input = Console.ReadLine();

            string input = System.Threading.Interlocked.Increment(ref currentOrdinalValue).ToString();



            Activity activity = CreateWorkflow();

            WorkflowApplication application = new WorkflowApplication(activity);

            application.InstanceStore = instanceStore;



            application.Completed = (workflowApplicationCompletedEventArgs) =>

            {                

                Console.WriteLine("\nWorkflowApplication has Completed in the {0} state.", workflowApplicationCompletedEventArgs.CompletionState);

            };



            application.Unloaded = (workflowApplicationEventArgs) =>

            {

                Console.WriteLine("WorkflowApplication has Unloaded\n");

                instanceUnloaded.Set();

            };



            application.Load(id);



            //this resumes the bookmark setup by readline

            application.ResumeBookmark(readLineBookmark, input);



            instanceUnloaded.WaitOne();

        }



        static Sequence CreateWorkflow()

        {

            Variable<string> response = new Variable<string>();



            return new Sequence()

            {

                Variables = { response },

                Activities = { 

                        new WriteLine(){

                            Text = new InArgument<string>("What is your name?")},

                        new ReadLine(){ 

                            BookmarkName = readLineBookmark, 

                            Result = new OutArgument<string>(response)},

                        new WriteLine(){

                            Text = new InArgument<string>((context) => "Hello " + response.Get(context))}}

            };

        }



        private static void SetupInstanceStore()

        {

            //instanceStore = 

            //    new SqlWorkflowInstanceStore(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SampleInstanceStore.mdf;Integrated Security=True;User Instance=True");

            instanceStore =

                new SqlWorkflowInstanceStore(@"Data Source=.;Initial Catalog=Persistence;Integrated Security=True;MultipleActiveResultSets=True;Async=true");



            InstanceView view = instanceStore.Execute(instanceStore.CreateInstanceHandle(), new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30));

            instanceStore.DefaultInstanceOwner = view.InstanceOwner;

        }

    }

}<br/>

推荐答案

您好,

您的工作流程在尝试再次加载时已经完成.该实例应在持久性数据库中处于可运行状态,以便再次加载.另外,您将在所有100000个实例之间共享等待事件,这意味着在我们阻止事件返回时,随时可能只有一个实例在运行.我看到了失败的调用堆栈,但是那里没有异常.您能否指出实际示例和例外情况?


这篇关于WF 4.0 Beta 2中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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