Hi, I have an MVC 3 application implemented with Unity that disposes the context after each http request. I want to trigger some time consuming tasks using Task.Factory.StartNew. However when my asynchronous task is executed I receive this error: "The
operation cannot be completed because the DbContext has been disposed.". It's clear for me what is happening but I don't know how to create a new dbcontext for my time consuming task.
The pice of my code that calls the time consuming task is:
yyie
0 Points
1 Post
Asynchronous thread in MCV3 with Unity
Jun 04, 2012 03:24 PM|LINK
Hi, I have an MVC 3 application implemented with Unity that disposes the context after each http request. I want to trigger some time consuming tasks using Task.Factory.StartNew. However when my asynchronous task is executed I receive this error: "The operation cannot be completed because the DbContext has been disposed.". It's clear for me what is happening but I don't know how to create a new dbcontext for my time consuming task.
The pice of my code that calls the time consuming task is:
System.Threading.Tasks.Task.Factory.StartNew(delegate { this.Using<AlertRun>().Execute(id, notificationType); });