• 多线程同步


    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;
            }
  • 相关阅读:
    Vue Hooks
    React初识-Hooks
    React-JSX初识
    css基础知识
    发布-订阅者模式
    Map和Set
    数据类型
    tcp三次握手以及tcp三次握手一句话总结
    网页布局相关
    浏览器渲染页面的流程
  • 原文地址:https://www.cnblogs.com/daixingqing/p/4437271.html
Copyright © 2020-2023  润新知