public static class Program {
|
public static async Task Main() {
|
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
|
var mongoClient = new MongoClient("mongodb+srv://username:password@instance.mongodb.net/Database");
|
var database = mongoClient.GetDatabase("Database");
|
var collection = database.GetCollection<object>("Collection");
|
var count = await collection.CountDocumentsAsync(f => true);
|
Console.WriteLine($"Document count: {count}");
|
|
Console.WriteLine("Stop server or disconnect from the internet now");
|
Debugger.Break();
|
|
try {
|
var count2 = await collection.CountDocumentsAsync(f => true);
|
Console.WriteLine($"Document count: {count2}");
|
} catch {
|
// Do nothing, this is expected to fail
|
}
|
Console.ReadLine();
|
}
|
|
private static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) {
|
// This should never be called, but it is
|
Console.WriteLine($"UnobservedTaskException: {sender.GetType()}\n{e.Exception}");
|
}
|
}
|