R – State Machine Persistence WorkFlow

workflowworkflow-foundation

Hey all, I have created a WinForms to handle Persistence Activities using the Windows WorkFlow Foundation. I'm using the .NET 3.0 SQL and VS2005 as the IDE with C# as the code language. Also, the environment is mandated to me by the corporate policy for development. So until the dinosaurs decide to upgrade, I'm stuck with VS2005.

My probelm is this, I'm able to work with 1 workflow at a time, and I'd like to be able to handle Multiple workflows. As in when I click the Submit button on my form, I'd like to be able to create a new WorkFlow instance.

I created the runtime and add all the appropriate services. I hook in persistence, and when I click the Submit I start an instance of the WorkFlow. I'm relatively new to the WorkFlow Foundation, and the MSDN links have provided little to no help for me. If anyone could put me in the right direciton within my source code, that would be helpful.

I have attached a link to the source for my project.

Click Here for the Source

Thanks in Advance!

Best Answer

I had a look and it appears that you are creating a new workflow each time you click submit. I get a new instance id, which is a good sign :) PopulatePSUP(string instanceID) captures the instance id for the dropdown. But you are only storing one instance id at a time in Guid _instanceID. This form level variable is then used for all the button events. You could insead use the cboPSUPItems.Text.

Something like:

    private void btnPSUPApprove_Click(object sender, EventArgs e)
    {
        string instanceId = this.cboPSUPItems.Text;

        if ( instanceId.Length > 0 )
        {
            myArgs.Approved = true;
            approved = "Yes";
            this.resumeHistory[ instanceId ].Clear( );
            this.resumeHistory[ instanceId ].Add( "Name: " + applicantName );
            this.resumeHistory[ instanceId ].Add( "Email:" + applicantEmail );
            this.resumeHistory[ instanceId ].Add( "Text:" + applicantText );
            this.resumeHistory[ instanceId ].Add( "Approved:" + approved );
            this.resumeHistory[ instanceId ].Add( "Denied:" + denied );
            this.resumeHistory[ instanceId ].Add( "PD Approval Requested:" + pDRequest );
            resumeService.RaisePSUPApprovedEvent( new Guid(instanceId) , myArgs );
            this.cboPSUPItems.Items.Remove( this.cboPSUPItems.SelectedItem );
            txtPSUPNotes.Clear( );
        }
    }

You might want to think about using a collection/list to store the instanceIds in as well. For any workflow wide logic.

Something like:

List<Guid> _instanceIds = new List<Guid>( );

...

_instanceIds.Add( instance.InstanceId );
Related Topic