VS2010中查找阻塞调用解决方案
我的任务是从 C# 应用程序中删除阻塞调用。事实证明,这是它将运行的环境的要求。我了解阻塞调用的概念,但是,我不确定从哪里开始查找现有的阻塞调用。
那么有几个问题:
- 对于任何给定的函数,我如何判断它是否阻塞?除了查文档还有什么办法吗?
- 有什么方法可以搜索项目或解决方案中的阻塞吗?例如。有什么插件可以告诉我吗?
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:
- For any given function, how can I tell whether or not it is blocking? Is there any way besides looking up the documentation?
- Is there any way to search for blocking in a project or solution? Eg. some plug-in that could tell me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,没有自动方法可以找到阻塞呼叫。大多数阻塞代码用于线程或进程同步,例如锁、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.