如何使用AOP分享不同的线程之间的数据在C#中? [英] How to share data between different threads In C# using AOP?

查看:201
本文介绍了如何使用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.

您也可以只直接访问(当然适当的锁)的数据成员,如果你使用的<一个实例的形式启动线程href=\"http://msdn.microsoft.com/en-us/library/system.threading.threadstart.aspx\"><$c$c>ThreadStart委派。

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.

这篇关于如何使用AOP分享不同的线程之间的数据在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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