开发者

How to spawn a new thread from RIA Domain Service

开发者 https://www.devze.com 2023-03-06 22:03 出处:网络
My team and I are working on an application that accesses a \"huge\" database, roughly 32M rows in 8 months. The application is a RIA Domain Service application. We have optimized the application and

My team and I are working on an application that accesses a "huge" database, roughly 32M rows in 8 months. The application is a RIA Domain Service application. We have optimized the application and the database design in such a way that even on a box with very limited resources the response time is never more than few seconds.

However, there are certain tasks that need to be performed on a large record set (at least 2-3M records per operation). An example is the generation of a monthly report. Definitely we cannot keep the application waiting for a result, because i开发者_如何转开发t would hit either the 30 seconds timeout.

After reading this post, I thought I could create an [Invoke] method, which spawns a new thread, and consequently it would free the client up. The thread would be in charge of extracting data from the DB and writing them nicely in a PDF. I've tried to implement this scenario, but I get an exception, which says that the underlying connection has already been disposed...

Is this approach correct? Can I achieve what I am trying to do or there is some issue I cannot overcome? And is there any better way to do this?

Cheers, Gianluca.


Ok, I've realized my question is a bit silly.

As far as I understood, the ObjectContext exists as long as the client is connected, otherwise it gets disposed. Because I was writing an Invoke method that does not require any change tracking, I have resolved by: - spawning a new thread from within the Invoke method - instantiating a new EF context inside the worker thread - disposing the new EF context as soon as the separate thread operation is terminated.

Cheers, Gianluca.

0

精彩评论

暂无评论...
验证码 换一张
取 消