VS2010中查找阻塞调用解决方案

发布于 2024-11-24 07:28:24 字数 200 浏览 0 评论 0原文

我的任务是从 C# 应用程序中删除阻塞调用。事实证明,这是它将运行的环境的要求。我了解阻塞调用的概念,但是,我不确定从哪里开始查找现有的阻塞调用。

那么有几个问题:

  1. 对于任何给定的函数,我如何判断它是否阻塞?除了查文档还有什么办法吗?
  2. 有什么方法可以搜索项目或解决方案中的阻塞吗?例如。有什么插件可以告诉我吗?

I've been tasked with removing blocking calls from a C# app. Turns out this is a requirement of the environment it'll be running on. I understand the concept of a blocking call, however, I'm not sure where to begin finding existing blocking calls.

So a few questions:

  1. For any given function, how can I tell whether or not it is blocking? Is there any way besides looking up the documentation?
  2. Is there any way to search for blocking in a project or solution? Eg. some plug-in that could tell me?

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

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

发布评论

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

评论(1

帅的被狗咬 2024-12-01 07:28:24

据我所知,没有自动方法可以找到阻塞呼叫。大多数阻塞代码用于线程或进程同步,例如锁、Monitor.Enter、Mutex 和 Semaphore/SemaphoreSlim 等待、CountdownEvent 和 Barrier 类的使用。还有 SpinLock 和 ReaderWriterLock/ReaderWriterLockSlim 锁定哪个块。

有几个线程调用处于阻塞状态。从技术上讲,Thread.Sleep 可以被视为阻塞调用,尽管它持续有限的时间。 Thread.Join 等待其他线程完成,因此处于阻塞状态。

For 和 While 循环可以被视为阻塞,因为它们将一直运行直到完成,但如果它们正在等待另一个线程中更新的特定变量,通常它们会使用上面的调用之一(尤其是锁定)。

请记住,删除其中任何一个都可能对线程安全产生严重的负面影响。

There's no automatic way I know of to find blocking calls. Most blocking code is used for thread or process synchronization such as lock, Monitor.Enter, Mutex and Semaphore/SemaphoreSlim waits, CountdownEvent and Barrier class use. There's also SpinLock and ReaderWriterLock/ReaderWriterLockSlim locks which block.

There are several Thread calls that are blocking. Thread.Sleep can technically be considered a blocking call, though it lasts a finite amount of time. Thread.Join waits for other threads to finish and is thus blocking.

For and While loops can be considered blocking as they will run until they are done, but usually they will use one of the calls above (especially lock) if they are waiting on a specific variable updated in another thread.

Keep in mind that removing any of these is likely to have a serious negative impact on thread safety.

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