views:

184

answers:

1

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!

A: 

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 );
MarcLawrence
Hey Thanks for the reply Marc. I'm using this as a test application to get familiar with the WorkFlow Foundation. After looking over what I did again you're right. I've removed using the _instaneID variable, and pass in the dropdown text with each subsequent event being raised. What I'm wondering is how can I grab the existing workflows from the database and populate the info as such? I'm thinking of Handling each event and storing data to a database. Is such a thing possible?
AProgrammer
Sure. I think the issue you will run into is figuring out what state a specific workflow is in. The workflow state is persisted as serialized data in a binary field, so it would be difficult to determine which id belongs to what state. You might find it easiest to track that externally.This post does a quick overview of persistence in action and is a good place to start:http://blogs.msdn.com/kaevans/archive/2008/12/09/understanding-persistence-in-windows-workflow-foundation.aspx
MarcLawrence