如何使用AOP分享不同的线程之间的数据在C#中?

问题描述:

如何在不使用静态变量共享不同的线程在C#之间的数据?
我们可以创建一个这样的机理使用属性?

How to share data between different threads In C# without using the static variables? Can we create a such machanism using attribute?

威尔面向方面在这种情况下编程帮助?

Will Aspect oriented programming help in such cases?

要达致这所有不同的线程应该单个对象的工作?

To acheive this all the different threads should work on single object?

您可以传递一个对象作为参数传递给的 Thread.Start ,并把它作为当前线程和线程启动之间的共享数据存储。

You can pass an object as argument to the Thread.Start and use it as a shared data storage between the current thread and the initiating thread.

您也可以只直接访问(当然适当的锁)的数据成员,如果你使用的ThreadStart$c$c>委派。

You can also just directly access (with the appropriate locking of course) your data members, if you started the thread using the instance form of the ThreadStart delegate.

您不能使用属性来创建线程之间共享的数据。您可以使用连接到您的类作为数据存储的属性情况,但我看不出这比使用静态或实例数据成员更好。

You can't use attributes to create shared data between threads. You can use the attribute instances attached to your class as a data storage, but I fail to see how that is better than using static or instance data members.