To enable workflow when updating splistitem:
Method 1:
Const string wf_guid = "{4e8dd7d8-aaa3-48d9-b012-fb2694ceb0fd }";
Const string wf_name = "wf_testing ";
Spworkflowmanager objwfmanager = NULL;
Spworkflowassociationcollection ob1_fasscol = NULL;
Objwfmanager = item. Web. Site. workflowmanager;
Ob1_fasscol = item. parentlist. workflowassociations;
Foreach (spworkflowassociation objwfass in ob1_fasscol)
{
If (string. Compare (objwfass. baseid. tostring ("B"), wf_guid, true) = 0)
// If (string. Compare (objwfass. Name, wf_name, true) = 0)
{
Objwfmanager. startworkflow (item, objwfass, objwfass. associationdata, true );
Break;
}
}
Method 2:
// Const string wf_guid = "3f0acaa4-bbb6-480c-a6d1-3e674011923a ";
/// Spworkflowassociation workflowassociation = mylist. workflowassociations [New GUID (wf_guid)];
// Occur: failed on START (retrying), completed after 2 minutes
String wf_name = system. configuration. configurationmanager. receivettings ["wf_name_updatelistitem"];
If (wf_name = NULL | wf_name = "")
{
Wf_name = "wf_testing ";
}
Spworkflowassociation workflowassociation = mylist. workflowassociations. getassociationbyname (wf_name, system. Threading. thread. currentthread. currentculture );
Myweb. Site. workflowmanager. startworkflow (item, workflowassociation, workflowassociation. associationdata, true );
However, the previous two methods cause an error. After an error occurs, the value of workflow imported to the list item is changed to "failed on START (retrying )", however, it is strange that after about three minutes, workflow can be successfully run and its status changes to "completed ".
After finding this problem for a long time, I finally found a method, but it seems that because my workflow is directly created in the disigner, it may not be applicable because it is not a code establishment. As for how it really works, further research is required!
See:
Workflow "failed on START (retrying )"
Http://blogs.msdn.com/wael/archive/2008/01/11/workflow-failed-on-start-retrying.aspx