public static async void EnqueueConnect(IConnection connection, AsyncIOCallback callback, object state)
{
var data = ConnectCache.Dequeue().Initialise(connection, callback, state);
try
{
using (var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30.0)))
{
Interlocked.Increment(ref _halfOpens);
await connection.ConnectAsync(cancellationTokenSource.Token).ConfigureAwait(false);
}
FinishConnect(data);
}
catch
{
Interlocked.Decrement(ref _halfOpens);
callback(false, 0, state);
ConnectCache.Enqueue(data);
}
}