开发者

Waiting for completion of one-way WCF call in a C# console application

I have a WCF webservice (not under m开发者_运维问答y control) that implements functionality I need to access via IsOneWay=true + a callback interface, one of the methods of which notifies of processing completion. It has been written this way as it was initially designed for access from a GUI.

However I need to access this same method from a console application for use in a batch. Currently my crude method of achieving this is to set a flag to false and after calling the WCF method I implement a while loop with a brief Thread.Sleep() call in it. This obviously works but seems like a really poor way of achieving the end result.

I'd like to know what the proper way of doing this is. Note: the service is out of my control and the reference has just been added through the IDE although I can easily knockup a code implementation etc.


Use a ManualResetEvent for waiting for completion. Call the one-way async method on the service and then wait on the manualresetevent object. In your callback call the Set() method which will let your main thread continue execution after WaitOne() call like so:

var waitHandle = new ManualResetEvent();

yourwcfObject.CallTheOneWayMethod();
waitHandle.WaitOne();


void CallbackMethodRaisedByWCFService()
{
    waitHandle.Set();
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜