本文整理汇总了C#中MongoServerInstance.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# MongoServerInstance.Connect方法的具体用法?C# MongoServerInstance.Connect怎么用?C# MongoServerInstance.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoServerInstance
的用法示例。
在下文中一共展示了MongoServerInstance.Connect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Connect
internal void Connect(
TimeSpan timeout
) {
server.ClearInstances();
var exceptions = new List<Exception>();
foreach (var address in server.Settings.Servers) {
try {
var serverInstance = new MongoServerInstance(server, address);
server.AddInstance(serverInstance);
try {
serverInstance.Connect(server.Settings.SlaveOk); // TODO: what about timeout?
} catch {
server.RemoveInstance(serverInstance);
throw;
}
return;
} catch (Exception ex) {
exceptions.Add(ex);
}
}
var innerException = exceptions.FirstOrDefault();
var connectionException = new MongoConnectionException("Unable to connect to server", innerException);
if (exceptions.Count > 1) {
connectionException.Data.Add("exceptions", exceptions);
}
throw connectionException;
}
示例2: ConnectInstance
private void ConnectInstance(MongoServerInstance instance)
{
Interlocked.Increment(ref _outstandingInstanceConnections);
ThreadPool.QueueUserWorkItem(_ =>
{
try
{
instance.Connect();
}
catch
{
// instance is keeping it's last ConnectionException
}
finally
{
Interlocked.Decrement(ref _outstandingInstanceConnections);
}
});
}
示例3: ConnectInstance
private void ConnectInstance(MongoServerInstance instance)
{
_stateChangeQueue.EnqueuWorkItem(() =>
{
try
{
instance.Connect();
}
catch
{
// instance is keeping it's last ConnectionException
}
return instance;
});
}