Want to see the source code please directly to the end, using the way such as
If you need multiple bookmarks at the same time to create bookmarks directly in the desired location, you will be considered the same instance.
If the desired effect is to require several department audits at the same time, you can create multiple bookmarks at the same time in the corresponding location.
Writing a bookmark code activity
Note that there are several places where creating a bookmark requires inheriting nativeactivity, and then modifying the parameter type of Execute
All comments section below
Public Sealed classbookmarkactivity:nativeactivity {//defines an activity input parameter for a string type Publicinargument<string> Text {Get;Set; } Publicoutargument<string> bookmark{Get;Set;} //If the activity returns a value, the codeactivity<tresult>//and returns the value from the Execute method. //2. Modify the context type protected Override voidExecute (Nativeactivitycontext context) {//gets the run-time value of the Text input parameter stringText = context. GetValue ( This. Text); //3. Create bookmarks and set callback functions for bookmark recoveryContext. CreateBookMark ("name",NewBookmarkcallback (final)); } //4. Rewrite Caninduceidle protected Override BOOLCaninduceidle {Get { return true; } } //5. Automatically call this function to pass bookmarks to external variables by restoring bookmarks protected voidFinal (Nativeactivitycontext Context,bookmark Bookmark,Objectobj) {Dictionary<string,Object> o = (dictionary<string,Object>) obj; Context. SetValue (BookMark, context.) Activityinstanceid); }
1. Start the activity with Workflowapplication
//synchronize with main threadAutoResetEvent syncevent =NewAutoResetEvent (false); varact =NewActivity1 (); Dictionary<string,Object> dictionary =Newdictionary<string,Object>(); Dictionary. ADD ("pic","1"); Workflowapplication app=Newworkflowapplication (Act, dictionary); //Run Activityapp. Run (); //wait for the signalSyncevent.waitone ();
2. Persistent SQL path
C:\Windows\Microsoft.NET\Framework\v4. 0.30319
3. Add an assembly
3. Adding references
using System.Activities.DurableInstancing;
4. Bind data in a suitable location to persist the database used
Sqlworkflowinstancestore store = new Sqlworkflowinstancestore (@ "server=desktop-oigv51o\ sqlexpress;database=wftest;uid=sa;pwd=123"); // Binding Database App. Instancestore = store;
In this step of the database will be able to view the data, next to the desired location to get our bookmarks
5. Continue with the next steps
// Continue execution // Use the ID of the workflow in the database here instead of using the book signing app. Load (Guid.parse (TextBox2.Text)); App. Resumebookmark (TextBox1.Text,null);
Code: Download
Previous article:. NET WCF WF4.5
. NET WCF WF4.5 state machine, bookmarks and persistence