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


C# NpgsqlConnector.Reset方法代码示例

本文整理汇总了C#中Npgsql.NpgsqlConnector.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# NpgsqlConnector.Reset方法的具体用法?C# NpgsqlConnector.Reset怎么用?C# NpgsqlConnector.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Npgsql.NpgsqlConnector的用法示例。


在下文中一共展示了NpgsqlConnector.Reset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReleaseConnector

        /// <summary>
        /// Releases a connector, possibly back to the pool for future use.
        /// </summary>
        /// <remarks>
        /// Pooled connectors will be put back into the pool if there is room.
        /// </remarks>
        /// <param name="connection">Connection to which the connector is leased.</param>
        /// <param name="connector">The connector to release.</param>
        internal void ReleaseConnector(NpgsqlConnection connection, NpgsqlConnector connector)
        {
            Contract.Requires(connector.IsReady || connector.IsClosed || connector.IsBroken);

            ConnectorQueue queue;

            // Find the queue.
            // As we are handling all possible queues, we have to lock everything...
            lock (locker)
            {
                PooledConnectors.TryGetValue(connection.ConnectionString, out queue);
            }

            if (queue == null)
            {
                connector.Close(); // Release connection to postgres
                return; // Queue may be emptied by connection problems. See ClearPool below.
            }

            /*bool inQueue = false;

            lock (queue)
            {
                inQueue = queue.Busy.ContainsKey(Connector);
                queue.Busy.Remove(Connector);
            }
            */

            bool inQueue = queue.Busy.ContainsKey(connector);

            if (connector.IsBroken || connector.IsClosed)
            {
                if (connector.InTransaction)
                {
                    connector.ClearTransaction();
                }

                connector.Close();
                inQueue = false;
            }
            else
            {
                Contract.Assert(connector.IsReady);

                //If thread is good
                if ((Thread.CurrentThread.ThreadState & (ThreadState.Aborted | ThreadState.AbortRequested)) == 0)
                {
                    // Release all resources associated with this connector.
                    try {
                        connector.Reset();
                    } catch {
                        connector.Close();
                        inQueue = false;
                    }
                } else {
                    //Thread is being aborted, this connection is possibly broken. So kill it rather than returning it to the pool
                    inQueue = false;
                    connector.Close();
                }
            }

            // Check if Connector should return to the queue of available connectors. If not, this connector is invalid and should
            // only be removed from the busy queue which effectvely removes it from the pool.
            if (inQueue)
                lock (queue)
                {
                    queue.Busy.Remove(connector);
                    queue.Available.Enqueue(connector);
                }
            else
                lock (queue)
                {
                    queue.Busy.Remove(connector);
                }

            connector.ProvideClientCertificatesCallback = null;
            connector.UserCertificateValidationCallback = null;
        }
开发者ID:heianxing,项目名称:npgsql,代码行数:86,代码来源:NpgsqlConnectorPool.cs


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