Wf4 beta2 addedAsynccodeactivity,When writing a custom activity,YesBegin/end.When an asynchronous operation is executed, other activities in the workflow are not affected,
However, the workflow is not persistent.
The following is an example:
NamespaceCaryasync
{
Public Sealed Class Filewriter:Asynccodeactivity
{
PublicFilewriter ()
:Base()
{
}
Protected Override IasyncresultBeginexecute (AsynccodeactivitycontextContext,AsynccallbackCallback,ObjectState)
{
StringTempfilename =Path. Gettempfilename ();
Console. Writeline ("Writing to file :"+ Tempfilename );
FilestreamFile =File. Open (tempfilename,Filemode. Create );
Context. userstate = file;
Byte[] Bytes =Unicodeencoding. Unicode. getbytes ("123456789");
ReturnFile. beginwrite (bytes,0, Bytes. length, callback, State );
}
Protected Override VoidEndexecute (AsynccodeactivitycontextContext,IasyncresultResult)
{
FilestreamFile = (Filestream) Context. userstate;
Try
{
File. endwrite (result );
File. Flush ();
}
Finally
{
File. Close ();
}
}
}
}