.NET Framework 中线程安全类的示例?

发布于 2024-11-06 12:34:51 字数 128 浏览 1 评论 0原文

我目前正在编写应该是线程安全的代码。许多异步调用和事件以及通常需要大量工作才能保持同步和线程安全的东西。

.NET 框架中是否有任何类可以处理此类事情,我可以查看(反编译)这些类,以了解应该如何完成事情?确实越复杂越好...

I'm currently working on code which is supposed to be thread safe. Lots of asynchronous calls and events and stuff that generally requires quite a bit of work to keep synchronized and thread safe.

Are there any classes in the .NET framework which deal with this sort of thing, which I could look at (decompile), to see how things are supposed to be done? The more complex the better really...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如梦初醒的夏天 2024-11-13 12:34:51

.NET 4.0 线程安全集合

虽然面向 Windows 而不仅仅是 .NET 、Joe Duffy 的书值得注意:Windows 上的并发编程

.NET 4.0 Thread-Safe Collections

Though targeting Windows rather than just .NET, Joe Duffy's book is worth noting: Concurrent Programming on Windows

白衬杉格子梦 2024-11-13 12:34:51

MSDN 有一些关于 .NET 异步编程的好信息。查看异步编程设计模式

另请查看 监视器Mutex

MSDN has some good information on asynchronous programming in .NET. Check out Asynchronous Programming Design Patterns.

Also check out the Monitor and Mutex classes in System.Threading

一场春暖 2024-11-13 12:34:51

有几种方法可以使事物保持原子性。有些类支持防护,这样可以保证代码按特定顺序执行。您可以使用关键字 volatile 来确保变量访问是原子的(每次使用时从内存中读取)并且没有幻读。这些只是一些工具;我建议使用简单的 Google 搜索“atomic C#、F#..”

There are a few ways to keep things atomic. There are classes that support fencing, such that code is guaranteed to execute in a certain order. You can use the keyword volatile to ensure that variable access is atomic (Read from memory each use) and that you have no phantom reads. These are just a few tools; I would suggest a simple Google of "atomic C#, F#.."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文