Ejemplo n.º 1
0
        void container1()
        {
            //<snippet161>
            // A workflow is always run asychronously; the main thread waits on this event so the program
            // doesn't exit before the workflow completes
            workflowRuntime.AddService(new SqlWorkflowPersistenceService("Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;"));
            //</snippet161>

            //<snippet162>
            this.synchronizationScopeActivity = new System.Workflow.ComponentModel.SynchronizationScopeActivity();
            //</snippet162>

            //<snippet163>
            this.synchronizationScopeActivity.Activities.Add(this.throwsException);
            this.synchronizationScopeActivity.Name = "synchronizationScopeActivity";
            this.synchronizationScopeActivity.SynchronizationHandles = null;
            //</snippet163>
        }
        private void InitializeComponent()
        {
            parallel1 = new ParallelActivity();
            sequence1 = new SequenceActivity();
            sequence2 = new SequenceActivity();
            begin = new CodeActivity();
            end = new CodeActivity();
            increment1 = new CodeActivity();
            increment2 = new CodeActivity();
            decrement1 = new CodeActivity();
            decrement2 = new CodeActivity();
            SynchronizedDecrement = new SynchronizationScopeActivity();
            SynchronizedIncrement = new SynchronizationScopeActivity();
            System.Collections.Generic.List<string> stringCollection1 = new System.Collections.Generic.List<string>();
            System.Collections.Generic.List<string> stringCollection2 = new System.Collections.Generic.List<string>();

            this.CanModifyActivities = true;
            // parallel
            this.parallel1.Activities.Add(sequence1);
            this.parallel1.Activities.Add(sequence2);
            this.parallel1.Name = "parallel1";

            // sequences
            this.sequence1.Activities.Add(SynchronizedIncrement);
            this.sequence1.Name = "sequence1";
            this.sequence2.Activities.Add(SynchronizedDecrement);
            this.sequence2.Name = "sequence2";

            // both synchronization activities are set to  the same syncMutex string
            // in order for the parallel activity to provide synchronization guarantees for shared data access to count variable
            this.SynchronizedIncrement.Name = "SynchronizedIncrement";
            stringCollection1.Add("syncMutex");
            this.SynchronizedIncrement.SynchronizationHandles = stringCollection1;
            this.SynchronizedIncrement.Activities.Add(increment1);
            this.SynchronizedIncrement.Activities.Add(increment2);

            this.SynchronizedDecrement.Name = "SynchronizedDecrement";
            stringCollection2.Add("syncMutex");
            this.SynchronizedDecrement.SynchronizationHandles = stringCollection2;
            this.SynchronizedDecrement.Activities.Add(decrement1);
            this.SynchronizedDecrement.Activities.Add(decrement2);

            // code activities
            begin.Name = "begin";
            begin.ExecuteCode += new EventHandler(Begin_ExecuteCode);

            end.Name = "end";
            end.ExecuteCode += new EventHandler(End_ExecuteCode);

            increment1.Name = "increment1";
            increment1.ExecuteCode += new EventHandler(Increment1_ExecuteCode);

            increment2.Name = "increment2";
            increment2.ExecuteCode += new EventHandler(Increment2_ExecuteCode);

            decrement1.Name = "decrement1";
            decrement1.ExecuteCode += new EventHandler(Decrement1_ExecuteCode);

            decrement2.Name = "decrement2";
            decrement2.ExecuteCode += new EventHandler(Decrement2_ExecuteCode);

            // workflow activities
            this.Activities.Add(begin);
            this.Activities.Add(parallel1);
            this.Activities.Add(end);
            this.Name = "SynchronizedActivityWorkflow";
            this.CanModifyActivities = false;
        }
        private void InitializeComponent()
        {
            parallel1             = new ParallelActivity();
            sequence1             = new SequenceActivity();
            sequence2             = new SequenceActivity();
            begin                 = new CodeActivity();
            end                   = new CodeActivity();
            increment1            = new CodeActivity();
            increment2            = new CodeActivity();
            decrement1            = new CodeActivity();
            decrement2            = new CodeActivity();
            SynchronizedDecrement = new SynchronizationScopeActivity();
            SynchronizedIncrement = new SynchronizationScopeActivity();
            System.Collections.Generic.List <string> stringCollection1 = new System.Collections.Generic.List <string>();
            System.Collections.Generic.List <string> stringCollection2 = new System.Collections.Generic.List <string>();

            this.CanModifyActivities = true;
            // parallel
            this.parallel1.Activities.Add(sequence1);
            this.parallel1.Activities.Add(sequence2);
            this.parallel1.Name = "parallel1";

            // sequences
            this.sequence1.Activities.Add(SynchronizedIncrement);
            this.sequence1.Name = "sequence1";
            this.sequence2.Activities.Add(SynchronizedDecrement);
            this.sequence2.Name = "sequence2";

            // both synchronization activities are set to  the same syncMutex string
            // in order for the parallel activity to provide synchronization guarantees for shared data access to count variable
            this.SynchronizedIncrement.Name = "SynchronizedIncrement";
            stringCollection1.Add("syncMutex");
            this.SynchronizedIncrement.SynchronizationHandles = stringCollection1;
            this.SynchronizedIncrement.Activities.Add(increment1);
            this.SynchronizedIncrement.Activities.Add(increment2);

            this.SynchronizedDecrement.Name = "SynchronizedDecrement";
            stringCollection2.Add("syncMutex");
            this.SynchronizedDecrement.SynchronizationHandles = stringCollection2;
            this.SynchronizedDecrement.Activities.Add(decrement1);
            this.SynchronizedDecrement.Activities.Add(decrement2);

            // code activities
            begin.Name         = "begin";
            begin.ExecuteCode += new EventHandler(Begin_ExecuteCode);

            end.Name         = "end";
            end.ExecuteCode += new EventHandler(End_ExecuteCode);

            increment1.Name         = "increment1";
            increment1.ExecuteCode += new EventHandler(Increment1_ExecuteCode);

            increment2.Name         = "increment2";
            increment2.ExecuteCode += new EventHandler(Increment2_ExecuteCode);

            decrement1.Name         = "decrement1";
            decrement1.ExecuteCode += new EventHandler(Decrement1_ExecuteCode);

            decrement2.Name         = "decrement2";
            decrement2.ExecuteCode += new EventHandler(Decrement2_ExecuteCode);

            // workflow activities
            this.Activities.Add(begin);
            this.Activities.Add(parallel1);
            this.Activities.Add(end);
            this.Name = "SynchronizedActivityWorkflow";
            this.CanModifyActivities = false;
        }