本文整理汇总了C#中IConnection.Abort方法的典型用法代码示例。如果您正苦于以下问题:C# IConnection.Abort方法的具体用法?C# IConnection.Abort怎么用?C# IConnection.Abort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IConnection
的用法示例。
在下文中一共展示了IConnection.Abort方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SnapshotConnection
private void SnapshotConnection(IConnection upgradedConnection, IConnection rawConnection, bool isConnectionFromPool)
{
lock (this.ThisLock)
{
if (this.closed)
{
upgradedConnection.Abort();
if (isConnectionFromPool)
{
this.connectionPool.ReturnConnection(this.connectionKey, rawConnection, false, TimeSpan.Zero);
}
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationObjectAbortedException(System.ServiceModel.SR.GetString("OperationAbortedDuringConnectionEstablishment", new object[] { this.via })));
}
this.upgradedConnection = upgradedConnection;
this.rawConnection = rawConnection;
this.isConnectionFromPool = isConnectionFromPool;
}
}
示例2: CloseNoThrow
internal static void CloseNoThrow(IConnection connection, TimeSpan timeout)
{
bool success = false;
try
{
connection.Close(timeout, false);
success = true;
}
catch (TimeoutException)
{
}
catch (CommunicationException)
{
}
finally
{
if (!success)
{
connection.Abort();
}
}
}
示例3: ReleaseConnection
private void ReleaseConnection(bool abort, TimeSpan timeout)
{
string connectionKey;
IConnection upgradedConnection;
IConnection rawConnection;
lock (this.ThisLock)
{
this.closed = true;
connectionKey = this.connectionKey;
upgradedConnection = this.upgradedConnection;
rawConnection = this.rawConnection;
this.upgradedConnection = null;
this.rawConnection = null;
}
if (upgradedConnection != null)
{
try
{
if (this.isConnectionFromPool)
{
this.connectionPool.ReturnConnection(connectionKey, rawConnection, !abort, timeout);
}
else if (abort)
{
upgradedConnection.Abort();
}
else
{
this.connectionPool.AddConnection(connectionKey, rawConnection, timeout);
}
}
catch (CommunicationException exception)
{
if (DiagnosticUtility.ShouldTraceInformation)
{
DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
}
upgradedConnection.Abort();
}
}
}
示例4: SendFault
internal static void SendFault(IConnection connection, string faultString, byte[] drainBuffer, TimeSpan sendTimeout, int maxRead)
{
if (TD.ConnectionReaderSendFaultIsEnabled())
{
TD.ConnectionReaderSendFault(faultString);
}
EncodedFault encodedFault = new EncodedFault(faultString);
TimeoutHelper timeoutHelper = new TimeoutHelper(sendTimeout);
try
{
connection.Write(encodedFault.EncodedBytes, 0, encodedFault.EncodedBytes.Length, true, timeoutHelper.RemainingTime());
connection.Shutdown(timeoutHelper.RemainingTime());
}
catch (CommunicationException e)
{
DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
connection.Abort();
return;
}
catch (TimeoutException e)
{
if (TD.SendTimeoutIsEnabled())
{
TD.SendTimeout(e.Message);
}
DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
connection.Abort();
return;
}
// make sure we read until EOF or a quota is hit
int read = 0;
int readTotal = 0;
for (;;)
{
try
{
read = connection.Read(drainBuffer, 0, drainBuffer.Length, timeoutHelper.RemainingTime());
}
catch (CommunicationException e)
{
DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
connection.Abort();
return;
}
catch (TimeoutException e)
{
if (TD.SendTimeoutIsEnabled())
{
TD.SendTimeout(e.Message);
}
DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
connection.Abort();
return;
}
if (read == 0)
break;
readTotal += read;
if (readTotal > maxRead || timeoutHelper.RemainingTime() <= TimeSpan.Zero)
{
connection.Abort();
return;
}
}
ConnectionUtilities.CloseNoThrow(connection, timeoutHelper.RemainingTime());
}
示例5: SnapshotConnection
private void SnapshotConnection(IConnection upgradedConnection, IConnection rawConnection, bool isConnectionFromPool)
{
lock (ThisLock)
{
if (_closed)
{
upgradedConnection.Abort();
// cleanup our pool if necessary
if (isConnectionFromPool)
{
_connectionPool.ReturnConnection(_connectionKey, rawConnection, false, TimeSpan.Zero);
}
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
new CommunicationObjectAbortedException(
SR.Format(SR.OperationAbortedDuringConnectionEstablishment, _via)));
}
else
{
_upgradedConnection = upgradedConnection;
_rawConnection = rawConnection;
_isConnectionFromPool = isConnectionFromPool;
}
}
}
示例6: CloseNoThrow
internal static void CloseNoThrow(IConnection connection, TimeSpan timeout)
{
bool success = false;
try
{
connection.Close(timeout, false);
success = true;
}
catch (TimeoutException e)
{
if (TD.CloseTimeoutIsEnabled())
{
TD.CloseTimeout(e.Message);
}
DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
}
catch (CommunicationException e)
{
DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
}
finally
{
if (!success)
{
connection.Abort();
}
}
}
示例7: ShutdownAmqp
private void ShutdownAmqp(IConnection connection, ShutdownEventArgs reason)
{
// I can't make this NOT hang when RMQ goes down
// and then a log message is sent...
try
{
if (_Model != null && _Model.IsOpen
&& reason.ReplyCode != Constants.ChannelError
&& reason.ReplyCode != Constants.ConnectionForced)
_Model.Abort(); //_Model.Close();
}
catch (Exception e)
{
InternalLogger.Error("could not close model", e);
}
try
{
if (connection != null && connection.IsOpen)
{
connection.ConnectionShutdown -= ShutdownAmqp;
connection.Close(reason.ReplyCode, reason.ReplyText, 1000);
connection.Abort(1000); // you get 2 seconds to shut down!
}
}
catch (Exception e)
{
InternalLogger.Error("could not close connection", e);
}
}
示例8: Start
public void Start()
{
Int32 oldValue = Interlocked.CompareExchange(ref _runFlag, Running, Stopped);
if (Running == oldValue)
{
throw new InvalidOperationException("Can not call start twice concurrently on the same session");
}
do
{
try
{
_streamConnection = _httpInvoker.Connect(_baseUri, new StreamRequest(), _sessionId);
_eventStreamHandler.ParseEventStream(_streamConnection.GetTextReader());
}
catch (UnexpectedHttpStatusCodeException e)
{
if (Running == _runFlag && HttpStatusCode.Forbidden == e.StatusCode)
{
if (null != EventStreamSessionDisconnected)
{
EventStreamSessionDisconnected();
}
Interlocked.CompareExchange(ref _runFlag, Stopped, Running);
}
else if (Running == _runFlag && null != EventStreamFailed)
{
EventStreamFailed(e);
}
}
catch (Exception e)
{
if (Running == _runFlag && null != EventStreamFailed)
{
EventStreamFailed(e);
}
}
finally
{
if (null != _streamConnection)
{
_streamConnection.Abort();
_streamConnection = null;
}
}
} while (_restartStreamOnFailure && Running == _runFlag);
}