Hi I have a web service that is doing huge c开发者_C百科omputation and is taking more than a minute.
I have generated the proxy file of the web service and then from my client end I am using the dll(of course I generated the proxy dll).
My client side code is
TimeSeries3D t = new TimeSeries3D();
int portfolioId = 4387919;
string[] str = new string[2];
str[0] = "MKT_CAP";
DateRange dr = new DateRange();
dr.mStartDate = DateTime.Today;
dr.mEndDate = DateTime.Today;
Service1 sc = new Service1();
t = sc.GetAttributesForPortfolio(portfolioId, true, str, dr);
But since it is taking to much time for the server to compute, after 1 minute I am receiving an error message
The CLR has been unable to transition from COM context 0x33caf30 to COM context 0x33cb0a0 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.
Kindly guide me what to do?
Thanks
Are you calling this from within a UI thread? If so, that's the problem. Put long-running operations on background threads, then marshal calls back to the UI to update it (e.g. with BackgroundWorker
or Control.Invoke
.)
You need to refactor you service interface to have something like the Begin/End pattern, and do the long work in the thread pool.
So the client calls once to start the operation, the server runs this in the threadpool. Then, later, the client calls again to see if the process has completed (and get the results if it has).
If the long running task can report progress so the client gets more than "done"/"not done" so much the better.
精彩评论