本文整理汇总了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;
}
示例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();
}
}
示例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;
}
示例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);
}
}
示例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();
}
}
}
}
}
示例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),
示例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();
}
}
}
示例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();
}
示例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;
}
}
}
示例10: ReleaseConnection
private void ReleaseConnection(IConnection connection)
{
connection.Dispose();
}
示例11: CloseConnection
/// <summary>
/// �ر�����
/// </summary>
private void CloseConnection(IConnection connection)
{
try
{
if (connection != null)
{
connection.Close();
connection.Dispose();
GC.Collect();
}
}
catch
{
// ���Թر�֮ǰ�����ӡ����֮ǰ�������Ѿ��Ͽ������������쳣���ɺ��ԡ�
}
}
示例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
}
}
}
示例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();
示例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);
}
}