当静态对象在Visual Studio中同时运行时,是否共享静态对象?如果是这样,如何预防?

发布于 2025-02-09 20:25:26 字数 297 浏览 1 评论 0原文

虽然我认为将大型对象静态化是有效的,但我只是被告知应防止使用静态对象,因为在Visual Studio中,您无法控制哪些测试正在运行,并且测试可能会同时运行。这意味着可以同时访问和/或通过多个测试来访问静态对象。

有没有办法防止这种情况发生?我发现但似乎仅适用于字段变量。

While I was thinking it is is memory efficient to make large objects static, I was just told that using static objects should be prevented because in Visual Studio you can't control which tests are running and tests might run simultaneously. Meaning that the static object could be accessed and/or manipulated by multiple tests at the same time.

Is there a way to prevent that from happening? I found ThreadStaticAttribute but it seems to only work for field variables.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文