开发者

Switch to background thread and continue method execution

I have a deserialization method (XML) that functions well until it gets to X number of objects. Below X, the time is takes to deserialize is acceptable and the UI being blocked is not a problem. However, if the number of objects is greater than X (relatively unlikely, but possible), then the load time is too long. Is it possible to jump from the UI thread to a background thr开发者_开发问答ead once deserialization (or any other method) has started so that I can unlock the UI thread if the deserialization is taking too long? thanks


Just do the deserialization in a background thread in all cases. It won't be an issue if the number of objects is below X, and it won't block the UI if it is greater than X.

You can do it in a background worker, and use the result in the RunWorkerCompleted event (which is raised on the UI thread)


No, once you have requested deserialization from a BCL facility, you cannot switch the thread type. Perhaps if you wrote your own custom deserializer you could do this, but it would be far more effective to simply have a seperate thread (e.g. threadpool) do this task in all cases (on account of the big cases), rather than after you cross boundary X.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜