I’m using TPL to make async calls to a method in my DAL which fetches data from the backend. This works fine but occasionally an EntityCommandExecutionException exception is thrown with
There is already an open DataReader associated with this Command which
must be closed first.
message.
Obviously, this is caused by one thread trying to access the method of the same instance of a DAL object that another thread is still using so I resolved this by instantiating that DAL object every time a call is made and this solves the problem but I’m wondering if there is a way to solve this problem without having to instantiate the DAL object every time a call is made?
lock).