Some code example would be helpful, but I guess you have done something like this:
-
-
// wrap the delegate around the ipc call method
-
IpcChannelCallDelegate channelCall = new IpcChannelCallDelegate(channelCall);
-
// start the ipc call asychronously
-
IAsyncResult asyncResult = channelCall.BeginInvoke(param, null, null);
-
-
// -PLACEHOLDER-
-
-
// get the result from the ipc call
-
result = channelCall.EndInvoke(asyncResult);
-
-
Suppose now the ipc server goes down when the client code reaches the -PLACEHOLDER- the EndInvoke would return some mess.
One solution would be to add some timeout mechanism. Since you are using BeginInvoke and EndInvoke try this:
-
IpcChannelCallDelegate channelCall = new IpcChannelCallDelegate(channelCall);
-
IAsyncResult asyncResult = channelCall.BeginInvoke(param, null, null);
-
-
// this one is new:
-
while (!asyncResult.AsyncWaitHandle.WaitOne(5000, false))
if (!asyncResult.IsCompleted) throw new TimeoutException();
result = channelCall.EndInvoke(asyncResult); -
The while condition would evaluate after 5000 msec to true and if the asynchronous ipc call still yields no results a TimeoutException will be thrown, which you have to catch somewhere else.
And consider to use the ChannelServices.UnregisterChannel to avoid any new ipc calls after that exception.
Greetings,
K
Hi. I have two appications - a GUI and a main engine. The GUI talks to the engine using IPCChannels.
If I shutdown the engine, the GUI can still call a method on the interface provided by IPCChanel but it sits there forever. How can I detect if the engine (server) has shutdown?
I did try using BeginInvoke() on a delegate so that I could make my call asynchronously and then timeout after 'x' amount of time but then how do you stop an invoked IPCChannel call? I called EndInvoke() and this froze up my client GUI application.
Help would be really appreciated.
Thanks
Paul