Slow Operations In A RIA Services Domain Service Class

空扰寡人 提交于 2019-12-25 02:02:08

问题


sHi All,

I am using silverlight 3 with RIA services. I was wondering how I should deal with slow operations in a domain services class? I have an operation that will take a couple of minutes. I get a WCF timeout after a minute while the client is waiting for a response from the server.

Another approach perhaps? Is is possible to tell the domain services class to start an operation, and then poll the server every 5 seconds to see if it is finished.

I tried implementing this and the problem I ran into is that the domain service class is a new instance for every domain service method I call. It is stateless meaning that I cannot make the domain service start a thread with my operation, and later come and check up on it.

E.g.

Call domain service from client - 'start operation' (which starts a new thread)

Call domain service from client - 'is operation done' - this doesn't work because I am calling a new instance of the domain service

Any ideas?


回答1:


You could have your service operation return some kind of request identifier, stored in a static member (e.g. a dictionary associating the id with the request result and status) on your domain service. The service would spawn a thread to handle this request asynchronously (preventing the WCF timeout). The static member is updated by the thread when it is finished.

Then, you can poll from SilverLight using the identifier. New instances of the domain service would use the static member to return the status and result.



来源:https://stackoverflow.com/questions/2234321/slow-operations-in-a-ria-services-domain-service-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!