当前位置: 首页>>代码示例>>C#>>正文


C# Threading.LockCookie类代码示例

本文整理汇总了C#中System.Threading.LockCookie的典型用法代码示例。如果您正苦于以下问题:C# LockCookie类的具体用法?C# LockCookie怎么用?C# LockCookie使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LockCookie类属于System.Threading命名空间,在下文中一共展示了LockCookie类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Animate

 public static void Animate(Image image, EventHandler onFrameChangedHandler)
 {
     if (image != null)
     {
         ImageInfo item = null;
         lock (image)
         {
             item = new ImageInfo(image);
         }
         StopAnimate(image, onFrameChangedHandler);
         bool isReaderLockHeld = rwImgListLock.IsReaderLockHeld;
         LockCookie lockCookie = new LockCookie();
         threadWriterLockWaitCount++;
         try
         {
             if (isReaderLockHeld)
             {
                 lockCookie = rwImgListLock.UpgradeToWriterLock(-1);
             }
             else
             {
                 rwImgListLock.AcquireWriterLock(-1);
             }
         }
         finally
         {
             threadWriterLockWaitCount--;
         }
         try
         {
             if (item.Animated)
             {
                 if (imageInfoList == null)
                 {
                     imageInfoList = new List<ImageInfo>();
                 }
                 item.FrameChangedHandler = onFrameChangedHandler;
                 imageInfoList.Add(item);
                 if (animationThread == null)
                 {
                     animationThread = new Thread(new ThreadStart(ImageAnimator.AnimateImages50ms));
                     animationThread.Name = typeof(ImageAnimator).Name;
                     animationThread.IsBackground = true;
                     animationThread.Start();
                 }
             }
         }
         finally
         {
             if (isReaderLockHeld)
             {
                 rwImgListLock.DowngradeFromWriterLock(ref lockCookie);
             }
             else
             {
                 rwImgListLock.ReleaseWriterLock();
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:60,代码来源:ImageAnimator.cs

示例2: WriteLock

 /// <summary>
 /// Execute the action under a write lock
 /// </summary>
 /// <param name="cacheAction">The cache action.</param>
 public void WriteLock(CacheAction cacheAction)
 {
     if(readerWriterLock.IsWriterLockHeld)
     {
         cacheAction();
         return;
     }
     bool readerLockHeld = readerWriterLock.IsReaderLockHeld;
     LockCookie writerLock = new LockCookie();
     if (readerLockHeld)
     {
         writerLock = readerWriterLock.UpgradeToWriterLock(Timeout.Infinite);
     }
     else
         readerWriterLock.AcquireWriterLock(Timeout.Infinite);
     try
     {
         cacheAction();
     }
     finally
     {
         if (readerLockHeld)
             readerWriterLock.DowngradeFromWriterLock(ref writerLock);
         else
             readerWriterLock.ReleaseWriterLock();
     }
 }
开发者ID:nigthwatch,项目名称:rhino-dsl,代码行数:31,代码来源:AbstractLockable.cs

示例3: Equals

		public bool Equals (LockCookie obj)
		{
			if (this.ThreadId == obj.ThreadId &&
			    this.ReaderLocks == obj.ReaderLocks &&
			    this.WriterLocks == obj.WriterLocks) {
				return(true);
			} else {
				return(false);
			}
		}
开发者ID:runefs,项目名称:Marvin,代码行数:10,代码来源:LockCookie.cs

示例4: Remove

 public void Remove(IPAddr ip)
 {
     try
     {
         locker.AcquireReaderLock(new TimeSpan(0, 1, 0));
         try
         {
             if (list.ContainsKey(ip))
             {
                 LockCookie lc = new LockCookie();
                 try
                 {
                     lc = locker.UpgradeToWriterLock(new TimeSpan(0, 1, 0));
                     try
                     {
                         list.Remove(ip);
                     }
                     finally
                     {
                         locker.DowngradeFromWriterLock(ref lc);
                     }
                 }
                 catch (ApplicationException e)
                 {
                     Logging.LogCenter.Instance.LogException(e);
                 }
             }
         }
         finally
         {
             locker.ReleaseReaderLock();
         }
     }
     catch (ApplicationException aex)
     {
         Logging.LogCenter.Instance.LogException(aex);
     }
 }
开发者ID:zzz654321,项目名称:fireBwall,代码行数:38,代码来源:IPLists.cs

示例5: RegisterHook

        public static void RegisterHook(ISkinHook client)
        {
            if (m_Clients.Contains(client))
                return;

            if (!m_FilterOnThread.ContainsKey(System.Threading.Thread.CurrentThread.GetHashCode()))
                HookThread();

            LockCookie cookie1 = new LockCookie();
            bool readerLockHeld = NonClientHook.rwClientsListLock.IsReaderLockHeld;

            if (readerLockHeld)
            {
                cookie1 = NonClientHook.rwClientsListLock.UpgradeToWriterLock(-1);
            }
            else
            {
                NonClientHook.rwClientsListLock.AcquireWriterLock(-1);
            }

            try
            {
                m_Clients.Add(client);
            }
            finally
            {
                if (readerLockHeld)
                {
                    NonClientHook.rwClientsListLock.DowngradeFromWriterLock(ref cookie1);
                }
                else
                {
                    NonClientHook.rwClientsListLock.ReleaseWriterLock();
                }
            }
        }
开发者ID:huamanhtuyen,项目名称:VNACCS,代码行数:36,代码来源:NonClientHook.cs

示例6: UpgradeToWriterLock

 public LockCookie UpgradeToWriterLock(int millisecondsTimeout)
 {
     LockCookie result = new LockCookie();
     this.FCallUpgradeToWriterLock(ref result, millisecondsTimeout);
     return result;
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:6,代码来源:ReaderWriterLock.cs

示例7: RestoreLockInternal

 private extern void RestoreLockInternal(ref LockCookie lockCookie);
开发者ID:randomize,项目名称:VimConfig,代码行数:1,代码来源:ReaderWriterLock.cs

示例8: RestoreLock

 public void RestoreLock(ref LockCookie lockCookie)
 {
     this.RestoreLockInternal(ref lockCookie);
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:4,代码来源:ReaderWriterLock.cs

示例9: GetLockCookie

		LockCookie GetLockCookie ()
		{
			LockCookie cookie = new LockCookie (Thread.CurrentThreadId);
			
			if (HasWriterLock())
				cookie.WriterLocks = -state;
			else {
				object locks = reader_locks [Thread.CurrentThreadId];
				if (locks != null) cookie.ReaderLocks = (int)locks;
			}
			return cookie;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:12,代码来源:ReaderWriterLock.cs

示例10: RestoreLock

		public void RestoreLock(ref LockCookie lockCookie)
		{
			lock (this) {
				if (lockCookie.WriterLocks != 0)
					AcquireWriterLock (-1, lockCookie.WriterLocks);
				else if (lockCookie.ReaderLocks != 0)
					AcquireReaderLock (-1, lockCookie.ReaderLocks);
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:9,代码来源:ReaderWriterLock.cs

示例11: DowngradeFromWriterLock

		public void DowngradeFromWriterLock(ref LockCookie lockCookie)
		{
			lock (this) {
				if (!HasWriterLock())
					throw new ApplicationException ("The thread does not have the writer lock.");
				
				state = lockCookie.ReaderLocks;
				reader_locks [Thread.CurrentThreadId] = state;
				if (readers > 0) {
					Monitor.PulseAll (this);
				}
				
				// MSDN: A thread does not block when downgrading from the writer lock, 
				// even if other threads are waiting for the writer lock
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:16,代码来源:ReaderWriterLock.cs

示例12: RestoreLock

 public void RestoreLock(ref LockCookie lockCookie)
 {
 }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:3,代码来源:System.Threading.ReaderWriterLock.cs

示例13: FCallReleaseLock

 private extern void FCallReleaseLock(ref LockCookie result);
开发者ID:randomize,项目名称:VimConfig,代码行数:1,代码来源:ReaderWriterLock.cs

示例14: ReleaseLock

 public LockCookie ReleaseLock()
 {
     LockCookie result = new LockCookie();
     this.FCallReleaseLock(ref result);
     return result;
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:6,代码来源:ReaderWriterLock.cs

示例15: Load

 public bool Load()
 {
     try
     {
         LockCookie upgrade = new LockCookie();
         bool upgraded = false;
         if (locker.IsReaderLockHeld)
         {
             upgrade = locker.UpgradeToWriterLock(new TimeSpan(0, 1, 0));
             upgraded = true;
         }
         else
             locker.AcquireWriterLock(new TimeSpan(0, 1, 0));
         try
         {
             try
             {
                 if (File.Exists(ConfigurationManagement.Instance.ConfigurationPath + Path.DirectorySeparatorChar + "IPLists.cfg"))
                 {
                     XmlSerializer serializer = new XmlSerializer(typeof(SerializableDictionary<string, IPList>));
                     TextReader reader = new StreamReader(ConfigurationManagement.Instance.ConfigurationPath + Path.DirectorySeparatorChar + "IPLists.cfg");
                     iplists = (SerializableDictionary<string, IPList>)serializer.Deserialize(reader);
                     reader.Close();
                     reader.Dispose();
                 }
                 else
                 {
                     iplists = new SerializableDictionary<string,IPList>();
                 }
             }
             catch (Exception e)
             {
                 Logging.LogCenter.Instance.LogException(e);
                 iplists = new SerializableDictionary<string, IPList>();
             }
         }
         finally
         {
             if (upgraded)
                 locker.DowngradeFromWriterLock(ref upgrade);
             else
                 locker.ReleaseWriterLock();
         }
         return true;
     }
     catch (ApplicationException ex)
     {
         Logging.LogCenter.Instance.LogException(ex);
         return false;
     }
 }
开发者ID:zzz654321,项目名称:fireBwall,代码行数:51,代码来源:IPLists.cs


注:本文中的System.Threading.LockCookie类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。