SimpleHybirdLock 类 |
命名空间: HslCommunication.Core
SimpleHybirdLock 类型公开以下成员。
名称 | 说明 | |
---|---|---|
SimpleHybirdLock | 初始化 SimpleHybirdLock 类的一个新实例 |
名称 | 说明 | |
---|---|---|
IsWaitting |
获取当前锁是否在等待当中 Gets whether the current lock is waiting | |
LockingTick |
获取当前进入等待锁的数量 Gets the number of pending locks currently entered | |
SimpleHybirdLockCount |
获取当前HslCommunication组件里正总的所有进入锁的信息 Gets the information about all incoming locks in the current HslCommunication component | |
SimpleHybirdLockWaitCount |
当前HslCommunication组件里正在等待的锁的统计信息,此时已经发生了竞争了 Statistics on locks currently waiting in the HslCommunication component are now in contention |
名称 | 说明 | |
---|---|---|
Dispose | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. | |
Enter |
获取锁,可以指定获取锁的超时时间,如果指定的时间没有获取锁,则返回False,反之,返回True To acquire a lock, you can specify the timeout period for acquiring a lock, return False if the specified time does not acquire a lock, and vice versa, return True | |
Equals | Determines whether the specified object is equal to the current object. (继承自 Object。) | |
GetHashCode | Serves as the default hash function. (继承自 Object。) | |
GetType | Gets the Type of the current instance. (继承自 Object。) | |
Leave |
离开锁 Leave the lock | |
ToString | Returns a string that represents the current object. (重写 ObjectToString.) |
名称 | 说明 | |
---|---|---|
ToJsonString |
获取当前对象的JSON格式表示的字符串。 (由 HslExtension 定义。)Gets the string represented by the JSON format of the current object. |
private SimpleHybirdLock simpleHybird = new SimpleHybirdLock( ); public void SimpleHybirdLockExample( ) { // 同步锁,简单的使用 simpleHybird.Enter( ); // do something simpleHybird.Leave( ); } public void SimpleHybirdLockExample2( ) { // 高级应用,锁的中间是不允许有异常发生的,假如方法会发生异常 simpleHybird.Enter( ); try { int i = 0; int j = 6 / i; simpleHybird.Leave( ); } catch { simpleHybird.Leave( ); throw; } // 这样做的好处是既没有吞噬异常,锁又安全的离开了 }