zoukankan      html  css  js  c++  java
  • 排他锁Lock

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            private static object WeixinPushHelperLock = new object();
            static void Main(string[] args)
            {
                for (int i = 0; i < 10; i++)//重复执行的方法
                {
                    NewMethod();
                }
            }
    
            private static void NewMethod()
            {
                if (Monitor.IsEntered(WeixinPushHelperLock)) return;//锁定中就return
                Monitor.Enter(WeixinPushHelperLock);
                //你的业务代码。。。
    
                Monitor.Exit(WeixinPushHelperLock);//执行完成后释放
            }
        }
    }
    
  • 相关阅读:
    2021/6/17学期总结
    2021/6/16申请加分
    2021/6/15
    2021/6/14
    2021/6/11
    2021/6/10
    2021/6/9
    2021/6/8
    2021/6/7
    2021/6/5读书笔记
  • 原文地址:https://www.cnblogs.com/Jerrycjc/p/6264101.html
Copyright © 2011-2022 走看看