简体   繁体   English

Mongo .Net Driver 如何关闭连接

[英]How Mongo .Net Driver closes the connection

I have an application that makes 5 queries at the same time and I might need to exit the application before all of them are done, I would like to know how can I cancel all current operations that my MongoClient is making and close the connection.我有一个同时进行 5 个查询的应用程序,我可能需要在所有查询完成之前退出该应用程序,我想知道如何取消我的 MongoClient 正在进行的所有当前操作并关闭连接。

From what I read at another question in stackoverflow, there's no need to close or dispose of connections in MongoClient because the client handles it automatically so the client will close the connection when the application exits but will the client wait for those queries to finish before closing automatically or will it immediately close?根据我在 stackoverflow 中的另一个问题中读到的内容,无需关闭或处理 MongoClient 中的连接,因为客户端会自动处理它,因此客户端将在应用程序退出时关闭连接,但客户端会在关闭之前等待这些查询完成自动还是会立即关闭? If it waits, how can I make it cancel those queries and close the connection immediately rather than waitting?如果它等待,我怎样才能让它取消这些查询并立即关闭连接而不是等待?

如果您需要强制处置 mongoClient,请尝试以下操作:

ClusterRegistry.Instance.UnregisterAndDisposeCluster(client.Cluster)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM