Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When starting a new workflow with WorkflowApplication in asynchronous way. From NativeActivity I canot gain the mainthread principal by using Thread.CurrentPrincipal. How to pass the mainthread principal to the workflow thread? Thanks!

The code to start a workflow:

C#
var wfApp = new WorkflowApplication(flowObject, inputs);

var syncConext = SynchronizationContext.Current;
wfApp.SynchronizationContext = syncConext;

wfApp.PersistableIdle = (e) =>
{
    insUnloaded.Set();
    return PersistableIdleAction.Unload;
};

wfApp.OnUnhandledException = (e) =>
{
    return UnhandledExceptionAction.Terminate;
};

wfApp.Aborted = (args) =>
{
    syncConext.OperationCompleted();
};

wfApp.Unloaded = (e) =>
{
    insUnloaded.Set();
};

wfApp.Completed = (e) =>
{
    syncConext.OperationCompleted();
};

wfApp.Run();

insUnloaded.WaitOne();


The Code in workflow NativeActivity :

C#
public class PortalActivity : NativeActivity
{
    protected override void Execute(NativeActivityContext context)
    {
       // SysPrincipal is a customized principal that implemented the IPrincipal interface,
       // the CurrentPrincipal of main thread has been set as this type of principal
       // here return null
       var principal = Thread.CurrentPrincipal as SysPrincipal;

       // ....
    }

    protected override bool CanInduceIdle
    {
        get
        {
            return true;
        }
    }

    #endregion
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900