如何以包括执行上下文自己的数据 [英] How to include own data in ExecutionContext

查看:87
本文介绍了如何以包括执行上下文自己的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,当你调用的BeginInvoke()或ThreadPool.QueueUserWorkItem(...).NET框架并行运行的一些方法获取包含$ C C接入安全信息和一些其他的东西$的ExecutionContext对象。

I know that when you run some method in parallel by calling BeginInvoke() or ThreadPool.QueueUserWorkItem(...) .NET framework is capturing ExecutionContext object that contains Code Access Security information and some other things.

我要的,是执行上下文,包括所需要我的并行算法的一些数据,但也必须捕捉,排队任务的那一刻。

What I want, is to include in ExecutionContext some data that is needed by my parallel method, but must be also captured at the moment of queuing the task.

问题是,并非总是我必须对所创建此并行任务的code控制,所以我必须找到一种方法之前,我把这种外部code来存储这些数据。这就是为什么我想到的ExecutionContext类。

Problem is that not always I do have control on the code that is creating this parallel task, so I must find a way to store this data before I call this external code. Thats why I thought about ExecutionContext class.

有没有办法通过一些状态的时候,我不能总在的code,它是一种将线程之间的工作控制的并行任务。

Is there any way to pass some state the parallel task when I'm not always in the control of the code that is splitting the work between threads.

推荐答案

发现:

CallContext.LogicalSetData(...)

(<一href="http://msdn.microsoft.com/en-ca/library/system.runtime.remoting.messaging.callcontext.logicalsetdata.aspx"相对=nofollow>文档)

CallContext.LogicalGetData(...)

(<一href="http://msdn.microsoft.com/en-ca/library/system.runtime.remoting.messaging.callcontext.logicalgetdata.aspx"相对=nofollow>文档)

这篇关于如何以包括执行上下文自己的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆