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


C# IConnection.Dispose方法代码示例

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


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

示例1: Close

        /// <summary>
        /// 
        /// </summary>
        /// <param name="connection"></param>
        /// <returns></returns>
        public virtual bool Close(IConnection connection)
        {
            if (connection.IsOpen)
                connection.Dispose();

            return true;
        }
开发者ID:KevinT,项目名称:fluentcassandra,代码行数:12,代码来源:ConnectionProvider.cs

示例2: Close

 /// <summary>
 /// Closes the connection.
 /// </summary>
 /// <param name="connection">
 /// The connection.
 /// </param>
 public override void Close(IConnection connection)
 {
     if (connection.Client.Connected)
     {
         connection.Dispose();
     }
 }
开发者ID:ereichert,项目名称:NoRM,代码行数:13,代码来源:NormalConnectionProvider.cs

示例3: ConnectionShutdown

 void ConnectionShutdown(IConnection connection, ShutdownEventArgs reason)
 {
     "The connection to the rabbitmq node is shutting down. \r\n\t Class: {0} \r\n\t Method: {1} \r\n\t Cause: {2} \r\n\t Reply {3}: {4}"
         .ToError<IBus>
         (
             reason.ClassId,
             reason.MethodId,
             reason.Cause,
             reason.ReplyCode,
             reason.ReplyText
         );
     connection.ConnectionShutdown -= ConnectionShutdown;
     _connection = null;
     connection.Dispose();
     connection = null;
 }
开发者ID:jcowart,项目名称:Symbiote,代码行数:16,代码来源:ConnectionManager.cs

示例4: EnqueueConnect

        public static void EnqueueConnect(IConnection connection, AsyncIOCallback callback, object state)
        {
            var data = connectCache.Dequeue().Initialise(connection, callback, state);

            try
            {
                var result = connection.BeginConnect(EndConnectCallback, data);
                Interlocked.Increment(ref halfOpens);
                ClientEngine.MainLoop.QueueTimeout(TimeSpan.FromSeconds(10), delegate
                {
                    if (!result.IsCompleted)
                        connection.Dispose();
                    return false;
                });
            }
            catch
            {
                callback(false, 0, state);
                connectCache.Enqueue(data);
            }
        }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:21,代码来源:NetworkIO.cs

示例5: Connect

        private void Connect()
        {
            if (connection == null || !connection.IsOpen)
            {
                lock (syncLock)
                {
                    if ((connection == null || !connection.IsOpen) && !(disposing || disposed))
                    {
                        if (connection != null)
                        {
                            try
                            {
                                // when the broker connection is lost
                                // and ShutdownReport.Count > 0 RabbitMQ.Client
                                // throw an exception, but before the IConnection.Abort()
                                // is invoked
                                // https://github.com/rabbitmq/rabbitmq-dotnet-client/blob/ea913903602ba03841f2515c23f843304211cd9e/projects/client/RabbitMQ.Client/src/client/impl/Connection.cs#L1070
                                connection.Dispose();
                            }
                            catch
                            {
                                if (connection.CloseReason != null)
                                {
                                    this.logger.InfoWrite("Connection '{0}' has shutdown. Reason: '{1}'",
                                        connection, connection.CloseReason.Cause);
                                }
                                else
                                {
                                    throw;
                                }
                            }

                        }

                        connection = connectionFactory.CreateConnection();
                        // A possible race condition exists during EasyNetQ IBus disposal where this instance's Dispose() method runs on another thread, while this thread is mid-executing connectionFactory.CreateConnection() (or a few lines earlier), and has not assigned the result to the connection variable before Dispose() accesses it.  This could result in the creation of a RabbitMQ.Client.IConnection instance which never gets disposed; that IConnection instance holds a thread open which can prevent application shutdown.  It was not desirable to lock (syncLock) within the Dispose() method to fix this; therefore, an additional check must be made here to dispose any such extra IConnection.
                        if (disposing || disposed)
                        {
                            connection.Dispose();
                        }
                    }
                }
            }
        }
开发者ID:sivesind,项目名称:EasyNetQ,代码行数:44,代码来源:DefaultConsumerErrorStrategy.cs

示例6: LoginAsync


//.........这里部分代码省略.........
                    {
                        LocaleId = "0x0409",
                        OsType = "winnt",
                        OsVersion = "5.0",
                        Architecture = "1386",
                        LibraryName = "MSMSGS",
                        ClientVersion = "5.0.0482",
                        ClientName = "WindowsMessenger",
                        LoginName = credentials.LoginName,
                    };

                    await responseTracker.GetResponseAsync<ClientVersionCommand>(clientVersionCommand, defaultTimeout);

                    var userCommand = new AuthenticateCommand("TWN", "I", credentials.LoginName);
                    var userResponse = await responseTracker.GetResponseAsync(userCommand, new Type[] { typeof(AuthenticateCommand), typeof(TransferCommand) }, defaultTimeout);

                    if (userResponse is AuthenticateCommand)
                    {
                        authTicket = (userResponse as AuthenticateCommand).Argument;
                    }

                    else if (userResponse is TransferCommand)
                    {
                        
                        TransferCommand transferResponse = userResponse as TransferCommand;

                        if (transferCount > 3)
                            throw new InvalidOperationException("The maximum number of redirects has been reached.");

                        transferCount++;

                        endPoint = SocketEndPoint.Parse(transferResponse.Host);

                        commandsDisposable.Dispose();

                        reader.Close();
                        writer.Close();
                        connection.Dispose();

                    }

                }

                PassportAuthentication auth = new PassportAuthentication();

                string authToken = await auth.GetToken(credentials.LoginName, credentials.Password, authTicket);

                var authCommand = new AuthenticateCommand("TWN", "S", authToken);
                var authResponse = await responseTracker.GetResponseAsync<AuthenticateCommand>(authCommand, defaultTimeout);

                var synCommand = new SynchronizeCommand(syncTimeStamp1 ?? "0", syncTimeStamp2 ?? "0");
                var synResponse = await responseTracker.GetResponseAsync<SynchronizeCommand>(synCommand, defaultTimeout);

                IDisposable syncCommandsSubscription = null;
                List<Command> syncCommands = null;

                if (synResponse.TimeStamp1 != syncTimeStamp1 || synResponse.TimeStamp2 != syncTimeStamp2)
                {

                    syncCommands = new List<Command>();

                    Type[] syncTypes = new Type[] { 
                        typeof(MessageCommand), 
                        typeof(UserCommand), 
                        typeof(GroupCommand), 
                        typeof(LocalPropertyCommand), 
开发者ID:kwerty,项目名称:Messenger-Library,代码行数:67,代码来源:MessengerClient.cs

示例7: TryToConnect

        void TryToConnect(object timer)
        {
            if(timer != null) ((Timer) timer).Dispose();

            logger.DebugWrite("Trying to connect");
            if (disposed) return;

            connectionFactory.Reset();
            do
            {
                try
                {
                    connection = connectionFactory.CreateConnection(); // A possible dispose race condition exists, whereby the Dispose() method may run while this loop is waiting on connectionFactory.CreateConnection() returning a connection.  In that case, a connection could be created and assigned to the connection variable, without it ever being later disposed, leading to app hang on shutdown.  The following if clause guards against this condition and ensures such connections are always disposed.
                    if (disposed)
                    {
                        connection.Dispose();
                        break;
                    }

                    connectionFactory.Success();
                    
                }
                catch (SocketException socketException)
                {
                    LogException(socketException);
                }
                catch (BrokerUnreachableException brokerUnreachableException)
                {
                    LogException(brokerUnreachableException);
                }
            } while (!disposed && connectionFactory.Next());

            if (connectionFactory.Succeeded)
            {
                connection.ConnectionShutdown += OnConnectionShutdown;
                connection.ConnectionBlocked += OnConnectionBlocked;
                connection.ConnectionUnblocked += OnConnectionUnblocked;

                OnConnected();
                logger.InfoWrite("Connected to RabbitMQ. Broker: '{0}', Port: {1}, VHost: '{2}'",
                    connectionFactory.CurrentHost.Host,
                    connectionFactory.CurrentHost.Port,
                    connectionFactory.Configuration.VirtualHost);
            }
            else
            {
                if (!disposed)
                {
                    logger.ErrorWrite("Failed to connect to any Broker. Retrying in {0} ms\n",
                        connectAttemptIntervalMilliseconds);
                    StartTryToConnect();
                }
            }
        }
开发者ID:fryderykhuang,项目名称:EasyNetQ,代码行数:54,代码来源:PersistentConnection.cs

示例8: Remove

        public void Remove(IConnection connection)
        {
            connection.Disconnected -= HandleDisconnected;

            lock (connections)
                foreach (var key in connections.Keys.ToArray())
                {
                    var list = connections[key];
                    var c = list.FindOrDefault(connection);
                    if (c != null)
                    {
                        if (list.Remove(c) && !list.Any())
                            connections.Remove(key);
                    }
                }
            connection.Dispose();
        }
开发者ID:stangelandcl,项目名称:Actors,代码行数:17,代码来源:ConnectionRouter.cs

示例9: Export

        internal void Export(string fileName)
        {
            if (File.Exists(fileName))
                File.Delete(fileName);

            /*
            IProviderRegistry pr = FeatureAccessManager.GetProviderRegistry();
            ProviderCollection pc = pr.GetProviders();
            MessageBox.Show("Number of providers=" + pc.Count);
            */

            try
            {
                IConnectionManager cm = FeatureAccessManager.GetConnectionManager();
                m_Connection = cm.CreateConnection("SDFProvider.dll");
                //m_Connection = cm.CreateConnection("OSGeo.SDF.3.6");
                //m_Connection = cm.CreateConnection("OSGeo.SQLite.3.6");
                RunExport(fileName);
                MessageBox.Show(String.Format("nok={0}  nFail={1}", m_NumOk, m_NumFail));
            }

            finally
            {
                if (m_Connection != null)
                {
                    m_Connection.Dispose();
                    m_Connection = null;
                }
            }
        }
开发者ID:steve-stanton,项目名称:backsight,代码行数:30,代码来源:SdfExporter.cs

示例10: ReleaseConnection

 private void ReleaseConnection(IConnection connection)
 {
     connection.Dispose();
 }
开发者ID:MingHuaL1,项目名称:Test,代码行数:4,代码来源:ConnectionPool.cs

示例11: CloseConnection

 /// <summary>
 /// �ر�����
 /// </summary>
 private void CloseConnection(IConnection connection)
 {
     try
     {
         if (connection != null)
         {
             connection.Close();
             connection.Dispose();
             GC.Collect();
         }
     }
     catch
     {
         // ���Թر�֮ǰ�����ӡ����֮ǰ�������Ѿ��Ͽ������������쳣���ɺ��ԡ�
     }
 }
开发者ID:joeiren,项目名称:quant_mq,代码行数:19,代码来源:MQConnection.cs

示例12: DisposeConnection

        private static void DisposeConnection(IConnection connection)
        {
            if (connection != null)
            {

                try
                {
                    connection.Close();
                }
                catch
                {
                    //TODO: Log Error
                }

                try
                {
                    connection.Dispose();
                }
                catch
                {
                    //TODO: Log Error
                }
            }
        }
开发者ID:bestwpw,项目名称:RestBus,代码行数:24,代码来源:AmqpChannelPooler.cs

示例13: buttonValidate


//.........这里部分代码省略.........
                    double beforePeak = Convert.ToDouble(offpeak.Hours - startTime.TimeOfDay.Hours);
                    TravelCost += beforePeak * rate2;
                    double afterPeak = Convert.ToDouble(endTime.TimeOfDay.Hours - offpeak.Hours);
                    TravelCost += afterPeak * rate1;
                }
                else
                    if ((IsTimeOfDayBetween(startTime, onpeak, offpeak)) && (IsTimeOfDayBetween(endTime, onpeak, offpeak)))
                    {
                        TravelCost += destTime * rate1;
                    }
                    else
                        TravelCost += destTime * rate2;
            #endregion
            //
            // Price calculation logic
            //
            #region Message Queue
            connectionFactory = new ConnectionFactory(BROKER, CLIENT_ID);
            connection = connectionFactory.CreateConnection();
            connection.Start();
            session = connection.CreateSession();
            subscriber = new Subscriber(session, TOPIC_NAME);
            subscriber.Start(CONSUMER_ID);
            subscriber.OnMessageReceived += new MessageReceivedDelegate(subscriber_OnMessageReceived);

            using (var publisher = new Publisher(session, TOPIC_NAME))
            {
                publisher.SendMessage(TravelCost.ToString());
            }

            Thread.Sleep(1000);
            try
            {
                subscriber.Dispose();
                session.Close();
                session.Dispose();
                connection.Stop();
                connection.Close();
                connection.Dispose();
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }

            #endregion
            //
            // Rebate Processor
            //
            #region Rebate Processor
            // Fetch membership class
            conn.Open();
            SqlDataReader rdr = null;
            cmd = new SqlCommand("SELECT * FROM membership WHERE [email protected]", conn);
            cmd.Parameters.AddWithValue("@Id", txtMemberId.Text);
            rdr = cmd.ExecuteReader();
            rdr.Read();
            string memclass = rdr.GetString(3);
            conn.Close();

            // Obtain order status
            conn.Open();
            rdr = null;
            cmd = new SqlCommand("SELECT * FROM booking WHERE [email protected]", conn);
            cmd.Parameters.AddWithValue("@Id", txtMemberId.Text);
            rdr = cmd.ExecuteReader();
开发者ID:nathard,项目名称:TruckHire,代码行数:67,代码来源:Default.aspx.cs

示例14: Release

 public void Release(IConnection conn)
 {
     lock (registry)
     {
         conn.Close();
         conn.Dispose();
         foreach (string name in registry.Keys)
         {
             if (registry[name] == conn)
             {
                 registry.Remove(name);
                 break;
             }
         }
         references.Remove(conn);
     }
 }
开发者ID:leaker,项目名称:fuhj-widgets,代码行数:17,代码来源:ConnectionPool.cs


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