當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。