是的DbContext线程安全的? [英] Is DbContext thread safe?

查看:432
本文介绍了是的DbContext线程安全的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在想,如果在的DbContext 类是线程安全的,我假设它不是,因为我目前正在执行访问paralell线程的DbContext 在我的应用程序,我得到锁定异常和其他东西的主机,看上去就像他们可能线程相关的。

I was wondering if the DbContext class is thread safe, I am assuming it's not, as I am currently executing paralell threads that access the DbContext in my application and I am getting a host of locking exceptions and other things that look like they may be thread related.

直到最近我没有得到任何错误......但直到最近我没有访问的DbContext 中的线程。

Until recently I wasn't getting any errors...but until recently I wasn't accessing the DbContext in the threads.

如果我是正确的,那会人建议作为一个解决方案?

If I am right, what would people suggest as a solution?

推荐答案

这不是线程安全的。只需在您创建线程的DbContext 的新实例。

It's not thread safe. Simply create a new instance of DbContext in you thread.

这篇关于是的DbContext线程安全的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆