4
AsyncTaskCodeActivity在执行第一个await后访问上下文参数时失败。例如:AsyncTaskCodeActivity和等待后丢失的上下文
public class TestAsyncTaskCodeActivity : AsyncTaskCodeActivity<int>
{
protected async override Task<int> ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
{
await Task.Delay(50);
// context has already been disposed and the next line throws
// ObjectDisposedException with the message:
// An ActivityContext can only be accessed within the scope of the function it was passed into.
context.Track(new CustomTrackingRecord("test"));
// more awaits can happen here
return 3;
}
}
是否有任何简单的方法来保存上下文,以便在等待某些内容后也可以使用它?
谢谢。我有一个类似的想法,但无法创建良好的实施。但是这个解决方案仍然有严重的局限我想过使用[AsyncNativeActivity](http://blogs.msdn.com/b/tilovell/archive/2011/06/09/wf4-they-have-asynccodeactivity-why-not-asyncnativeactivity.aspx)和一个自定义调度程序以便始终访问上下文。你怎么看? – arturek 2014-10-13 06:17:33
有什么限制? – 2014-10-17 18:34:42
自从你发布了这个版本已经过去了一年,但我在玩同样的问题。任何想法如何在这个游戏中正确处理ExecutionContext? – wasabi 2015-12-21 02:28:10