// Auto-generated, do not modify using System; using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; public static class MongoAsyncExt { public static Task CountAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Count(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task CountAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Count(query); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task CreateIndexAsync(this MongoCollection collection, MongoDB.Driver.IMongoIndexKeys keys, MongoDB.Driver.IMongoIndexOptions options) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.CreateIndex(keys, options); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task CreateIndexAsync(this MongoCollection collection, MongoDB.Driver.IMongoIndexKeys keys) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.CreateIndex(keys); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task CreateIndexAsync(this MongoCollection collection, System.String[] keyNames) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.CreateIndex(keyNames); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task> DistinctAsync(this MongoCollection collection, System.String key) { var tcs = new TaskCompletionSource>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Distinct(key); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task> DistinctAsync(this MongoCollection collection, System.String key, MongoDB.Driver.IMongoQuery query) { var tcs = new TaskCompletionSource>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Distinct(key, query); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task DropAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { collection.Drop(); tcs.SetResult(true); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task DropAllIndexesAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.DropAllIndexes(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task DropIndexAsync(this MongoCollection collection, MongoDB.Driver.IMongoIndexKeys keys) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.DropIndex(keys); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task DropIndexAsync(this MongoCollection collection, System.String[] keyNames) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.DropIndex(keyNames); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task DropIndexByNameAsync(this MongoCollection collection, System.String indexName) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.DropIndexByName(indexName); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task EnsureIndexAsync(this MongoCollection collection, MongoDB.Driver.IMongoIndexKeys keys, MongoDB.Driver.IMongoIndexOptions options) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { collection.EnsureIndex(keys, options); tcs.SetResult(true); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task EnsureIndexAsync(this MongoCollection collection, MongoDB.Driver.IMongoIndexKeys keys) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { collection.EnsureIndex(keys); tcs.SetResult(true); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task EnsureIndexAsync(this MongoCollection collection, System.String[] keyNames) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { collection.EnsureIndex(keyNames); tcs.SetResult(true); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task ExistsAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Exists(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task> FindAllAsAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.FindAllAs(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task FindAndModifyAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Driver.IMongoSortBy sortBy, MongoDB.Driver.IMongoUpdate update) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.FindAndModify(query, sortBy, update); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task FindAndModifyAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Driver.IMongoSortBy sortBy, MongoDB.Driver.IMongoUpdate update, System.Boolean returnNew) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.FindAndModify(query, sortBy, update, returnNew); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task FindAndModifyAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Driver.IMongoSortBy sortBy, MongoDB.Driver.IMongoUpdate update, System.Boolean returnNew, System.Boolean upsert) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.FindAndModify(query, sortBy, update, returnNew, upsert); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task FindAndModifyAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Driver.IMongoSortBy sortBy, MongoDB.Driver.IMongoUpdate update, MongoDB.Driver.IMongoFields fields, System.Boolean returnNew, System.Boolean upsert) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.FindAndModify(query, sortBy, update, fields, returnNew, upsert); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task FindAndRemoveAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Driver.IMongoSortBy sortBy) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.FindAndRemove(query, sortBy); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task> FindAsAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query) { var tcs = new TaskCompletionSource>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.FindAs(query); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task FindOneAsAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.FindOneAs(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task FindOneAsAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.FindOneAs(query); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task FindOneByIdAsAsync(this MongoCollection collection, MongoDB.Bson.BsonValue id) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.FindOneByIdAs(id); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task> GeoNearAsAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, System.Double x, System.Double y, System.Int32 limit) { var tcs = new TaskCompletionSource>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.GeoNearAs(query, x, y, limit); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task> GeoNearAsAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, System.Double x, System.Double y, System.Int32 limit, MongoDB.Driver.IMongoGeoNearOptions options) { var tcs = new TaskCompletionSource>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.GeoNearAs(query, x, y, limit, options); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task> GetIndexesAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.GetIndexes(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task GetStatsAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.GetStats(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task GetTotalDataSizeAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.GetTotalDataSize(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task GetTotalStorageSizeAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.GetTotalStorageSize(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task> GroupAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Bson.BsonJavaScript keyFunction, MongoDB.Bson.BsonDocument initial, MongoDB.Bson.BsonJavaScript reduce, MongoDB.Bson.BsonJavaScript finalize) { var tcs = new TaskCompletionSource>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Group(query, keyFunction, initial, reduce, finalize); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task> GroupAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Driver.IMongoGroupBy keys, MongoDB.Bson.BsonDocument initial, MongoDB.Bson.BsonJavaScript reduce, MongoDB.Bson.BsonJavaScript finalize) { var tcs = new TaskCompletionSource>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Group(query, keys, initial, reduce, finalize); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task> GroupAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, System.String key, MongoDB.Bson.BsonDocument initial, MongoDB.Bson.BsonJavaScript reduce, MongoDB.Bson.BsonJavaScript finalize) { var tcs = new TaskCompletionSource>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Group(query, key, initial, reduce, finalize); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task IndexExistsAsync(this MongoCollection collection, MongoDB.Driver.IMongoIndexKeys keys) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.IndexExists(keys); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task IndexExistsAsync(this MongoCollection collection, System.String[] keyNames) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.IndexExists(keyNames); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task IndexExistsByNameAsync(this MongoCollection collection, System.String indexName) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.IndexExistsByName(indexName); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task InsertAsync(this MongoCollection collection, T document) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Insert(document); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task InsertAsync(this MongoCollection collection, T document, MongoDB.Driver.SafeMode safeMode) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Insert(document, safeMode); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task> InsertBatchAsync(this MongoCollection collection, System.Collections.Generic.IEnumerable documents) { var tcs = new TaskCompletionSource>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.InsertBatch(documents); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task> InsertBatchAsync(this MongoCollection collection, System.Collections.Generic.IEnumerable documents, MongoDB.Driver.SafeMode safeMode) { var tcs = new TaskCompletionSource>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.InsertBatch(documents, safeMode); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task IsCappedAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.IsCapped(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task MapReduceAsync(this MongoCollection collection, MongoDB.Bson.BsonJavaScript map, MongoDB.Bson.BsonJavaScript reduce, MongoDB.Driver.IMongoMapReduceOptions options) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.MapReduce(map, reduce, options); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task MapReduceAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Bson.BsonJavaScript map, MongoDB.Bson.BsonJavaScript reduce, MongoDB.Driver.IMongoMapReduceOptions options) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.MapReduce(query, map, reduce, options); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task MapReduceAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Bson.BsonJavaScript map, MongoDB.Bson.BsonJavaScript reduce) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.MapReduce(query, map, reduce); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task MapReduceAsync(this MongoCollection collection, MongoDB.Bson.BsonJavaScript map, MongoDB.Bson.BsonJavaScript reduce) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.MapReduce(map, reduce); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task ReIndexAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.ReIndex(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task RemoveAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Remove(query); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task RemoveAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Driver.SafeMode safeMode) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Remove(query, safeMode); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task RemoveAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Driver.RemoveFlags flags) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Remove(query, flags); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task RemoveAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Driver.RemoveFlags flags, MongoDB.Driver.SafeMode safeMode) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Remove(query, flags, safeMode); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task RemoveAllAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.RemoveAll(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task RemoveAllAsync(this MongoCollection collection, MongoDB.Driver.SafeMode safeMode) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.RemoveAll(safeMode); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task ResetIndexCacheAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { collection.ResetIndexCache(); tcs.SetResult(true); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task SaveAsync(this MongoCollection collection, T document) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Save(document); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task SaveAsync(this MongoCollection collection, T document, MongoDB.Driver.SafeMode safeMode) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Save(document, safeMode); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task ToStringAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.ToString(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task UpdateAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Driver.IMongoUpdate update) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Update(query, update); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task UpdateAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Driver.IMongoUpdate update, MongoDB.Driver.SafeMode safeMode) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Update(query, update, safeMode); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task UpdateAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Driver.IMongoUpdate update, MongoDB.Driver.UpdateFlags flags) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Update(query, update, flags); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task UpdateAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, MongoDB.Driver.IMongoUpdate update, MongoDB.Driver.UpdateFlags flags, MongoDB.Driver.SafeMode safeMode) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Update(query, update, flags, safeMode); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task ValidateAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Validate(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task> FindAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query) { var tcs = new TaskCompletionSource>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.Find(query); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task> FindAllAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.FindAll(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task FindOneAsync(this MongoCollection collection) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.FindOne(); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task FindOneAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.FindOne(query); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task FindOneByIdAsync(this MongoCollection collection, MongoDB.Bson.BsonValue id) { var tcs = new TaskCompletionSource(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.FindOneById(id); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task> GeoNearAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, System.Double x, System.Double y, System.Int32 limit) { var tcs = new TaskCompletionSource>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.GeoNear(query, x, y, limit); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } public static Task> GeoNearAsync(this MongoCollection collection, MongoDB.Driver.IMongoQuery query, System.Double x, System.Double y, System.Int32 limit, MongoDB.Driver.IMongoGeoNearOptions options) { var tcs = new TaskCompletionSource>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.GeoNear(query, x, y, limit, options); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return tcs.Task; } }