线程锁,解决多线程并发问题

//全局变量,线程锁变量参数
private static int inTimerDelFile = 0;

/// <summary>
        
/// 删除文件
        
/// </summary>
        
/// <param name="source"></param>
        
/// <param name="e"></param>
        private static void DelFileEvent(object source, ElapsedEventArgs e)
        {
            try
            {
                if (Interlocked.Exchange(ref inTimerDelFile, 1) == 0)
                {
                    Model.DT_DECSERCONFIG tempDecSerConfig = _CurrentDecSerConfig;
                    JG.EWM.BLL.DeCodeBusiness.fDelFiles(tempDecSerConfig);

                    System.Threading.Thread.Sleep(5);
                    Interlocked.Exchange(ref inTimerDelFile, 0);
                }
            }
            catch (Exception ex)
            {
                Hzjg.Common.Utility.Log.fWriterLog("删除文件线程出错:", ex);
            }
        }
原文地址:https://www.cnblogs.com/zecVip/p/5091923.html