开发者

Calling a self-hosted WCF service in windows svc without blocking the UI

I have a WCF service hosted in a windows svc. I execute it in the normal way from a winforms app, making the channel etc, and then calling the method. There's no .svc file on the server side.

However, when I call the method in the windows service from the gui, this blocks the UI. Is there a way to do this without blocking the UI?

T开发者_JAVA百科hanks


Look at either the BackgroundWorker class, or the newer Task Parallel Library stuff. What you want is to fire off a call to the service, and describe what to do when the answer is received, but not block the UI while waiting for the answer. In some cases, there may be nothing for the UI to do while it waits for the answer, such as in the case of a search dialog. Until the answer comes back, there's really nothing else the UI can be doing. But executing the search in the background means that the UI thread has been freed. This means that you should still be able to move and resize the window, or possibly switch to another form in the same application while you wait. This is a good enough reason to execute the calls in the background.


Why don't you use the Async methods? For each method that is generated for you by the IDE, there is another method with Async suffix. This way you can asynchronously call the webservice.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜