本文整理汇总了C#中Cookie.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Cookie.Dispose方法的具体用法?C# Cookie.Dispose怎么用?C# Cookie.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cookie
的用法示例。
在下文中一共展示了Cookie.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Lock
public static Cookie Lock(object o) {
// Create the cookie which will release the lock.
#if DEBUG_LOCK_TRACE
LockTrace t;
lock(c_Traces.SyncRoot) {
t = GetTrace(o);
if(t == null)
c_Traces[new HashableWeakReference(o)] = t = new LockTrace(o);
}
Cookie cookie = new Cookie(o, t);
#else
Cookie cookie = new Cookie(o);
#endif
#if DEBUG_LOCK_CONTENTION
if(!Monitor.TryEnter(o)) {
Thread owner = t.Owner;
Debug.WriteLine(string.Format("Lock contention detected on object of type {0}:",
o.GetType().ToString()), t.GetType().ToString());
Debug.Indent();
try {
Debug.WriteLine(string.Format("Contending thread: {0}; Thread owning lock: {1}",
Thread.CurrentThread.Name, owner == null ? null : owner.Name));
} finally {
Debug.Unindent();
}
Monitor.Enter(o);
}
#else
// Acquire the lock.
Monitor.Enter(o);
#endif
try {
#if DEBUG_LOCK_TRACE
t.TraceEnter();
#endif
return cookie;
} catch {
// If there's an exception for any reason after the lock is acquired, make sure it's released.
cookie.Dispose();
throw;
}
}