C#相当于Java的等待和通知? [英] C# equivalent to java's wait and notify?
本文介绍了C#相当于Java的等待和通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道,它就像你可以在等待java和通知?
I am aware that you can lock an object in c# using lock but can you give up the lock and wait for something else to notify you that it's changed like you can in java with wait and notify?
在我看来,是同步的,并在Java和C#锁分别为同义。
It seems to me that synchronised and lock in java and c# respectively are synonomous.
推荐答案
等效功能(包括正常锁定)是在监控的类。
The equivalent functionality (including the normal locking) is in the Monitor class.
foo.notify() => Monitor.Pulse(foo)
foo.notifyAll() => Monitor.PulseAll(foo)
foo.wait() => Monitor.Wait(foo)
的
锁定
在C#中的语句等同于调用 Monitor.Enter
和 Monitor.Exit
用适当的try / finally块。
The lock
statement in C# is equivalent to calling Monitor.Enter
and Monitor.Exit
with an appropriate try/finally block.
See my threading tutorial or Joe Albahari's one for more details.
这篇关于C#相当于Java的等待和通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文