2
如果我手動運行此工作流程,它工作正常。當我讓它在編輯時自動運行SPContext.Current爲空。自動運行時如何訪問SPContext.Current?手動運行時工作流程具有SPContext.Current,但運行「On Change」時沒有?
如果我手動運行此工作流程,它工作正常。當我讓它在編輯時自動運行SPContext.Current爲空。自動運行時如何訪問SPContext.Current?手動運行時工作流程具有SPContext.Current,但運行「On Change」時沒有?
SharePoint在完全不同的進程下例行運行您的工作流程。至少,你可以期望你的工作流活動下出現:
owstimer.exe
過程,在相對於引發工作流程和的複雜的工作流程情況事件(!)的SharePoint選擇將實際執行它的進程。因此,從ASP.NET觸發的長時間運行的工作流程(即IIS工作進程)會自動重新計劃以在owstimer.exe
下運行。
結果是你不能使用SPContext.Current
。在工作流活動中,您必須使用WorkflowContext
實例,該實例提供了Web
屬性。您的活動必須聲明WorkflowContext
類型的依賴項屬性才能訪問它 - 詳情請參閱MSDN here。 VS項目模板將爲您提供必要的代碼。
實施例:
public partial class LogEventActivity: Activity
{
public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(LogEventActivity));
[Browsable(true)]
[ValidationOption(ValidationOption.Required)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public WorkflowContext __Context
{
get
{
return (WorkflowContext)base.GetValue(__ContextProperty);
}
set
{
base.SetValue(__ContextProperty, value);
}
}
}