zoukankan      html  css  js  c++  java
  • 多线程同步

    private System.Threading.ReaderWriterLock rwl;
            public DataBase()
            {
                rwl = new System.Threading.ReaderWriterLock();
            }
            /// <summary>
            /// 该方法Command执行ExecuteReader操作
            /// </summary>
            public IDataReader ExecSqlReader(string sqlText, List<IDbDataParameter> parameterList = null)
            {
                rwl.AcquireWriterLock(System.Threading.Timeout.Infinite);
                IDataReader drReader;
                SqlConnection(sqlText, false);
                AddParameter(parameterList);
                IDBConnection.Open();
                drReader = IDBCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                rwl.ReleaseWriterLock();
                return drReader;
            }
    private static object objLock = new object();
            /// <summary>
            /// 该方法Command执行ExecuteReader操作
            /// </summary>
            public IDataReader ExecSqlReader(string sqlText, List<IDbDataParameter> parameterList = null)
            {
                lock (objLock)
                {
                    IDataReader drReader;
                    SqlConnection(sqlText, false);
                    AddParameter(parameterList);
                    IDBConnection.Open();
                    drReader = IDBCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
    
                    return drReader;
                }
            }
    static int i = 0;
            /// <summary>
            /// 该方法Command执行ExecuteReader操作
            /// </summary>
            public IDataReader ExecSqlReader(string sqlText, List<IDbDataParameter> parameterList = null)
            {
                IDataReader drReader = null;
                while (true)
                {
                    if (i == 0)
                    {
                        System.Threading.Interlocked.Increment(ref  i);
                        SqlConnection(sqlText, false);
                        AddParameter(parameterList);
                        IDBConnection.Open();
                        drReader = IDBCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                        System.Threading.Interlocked.Decrement(ref  i);
                        break;
                    }
                }
                return drReader;
            }
  • 相关阅读:
    路由器远程登陆的方式
    路由器上的DNS服务器构建
    路由器配置维护技巧---管道的应用
    【转】常见面试问题
    英文面试决胜关键
    12个有趣的c语言面试题
    16道嵌入式C语言面试题(经典)
    LCD 调试总结
    关于uboot的一些优化
    linux驱动开发的经典书籍
  • 原文地址:https://www.cnblogs.com/daixingqing/p/4437271.html
Copyright © 2011-2022 走看看