Problem
The most reproducible scenario is starting the desktop application from a link on the tray application and then requesting the desktop application via a callback to do something. That virtually always throws a timeout error as other subsequent errors.
WCF Environment:
Server: A System Tray applet
Client: WinForms desktop application
Resources:
- WCF Interprocess Communcation
- Asynchronous Two-Way WCF Communication
- Three Ways to do WCF Instance Management
- Others
Method to Launch the Desktop Application from the Tray
// Start the process.
ProcessStartInfo oProcessInfo = new ProcessStartInfo()
{
FileName = regValue.ToString(),
WindowStyle = ProcessWindowStyle.Normal,
UseShellExecute = true,
CreateNoWindow = false,
};
Process oProcess = new Process()
{
StartInfo = oProcessInfo,
};
oProcess.Start();
I make several calls, but interaction does not necessarily fail on the first call. Here is a sample call:
var callback = IpcToTray.Callback;
if (null == callback)
return 0;
UInt16 idIsLaunched = callback.IsAppLaunched();
if (Id_AppIsLaunched == idIsLaunched)
return true;
I am using PerCall at the moment, but was using PerSession. Both did not help the cause any.
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class IpcToTray : IIpcToTray
{
}
Here are some of the errors:
System.TimeoutException
HResult=0x80131505
Message=This request operation sent to http://schemas.microsoft.com/2005/12/ServiceModel/Addressing/Anonymous did not receive a reply within the configured timeout (00:00:10). The time allotted to this operation may have been a portion of a longer timeout. This may be because the service is still processing the operation or because the service was unable to send a reply message. Please consider increasing the operation timeout (by casting the channel/proxy to IContextChannel and setting the OperationTimeout property) and ensure that the service is able to connect to the client.
Source=mscorlib
StackTrace:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at MyAppIpc.IIpcCallbackToTray.GetMyAppMode()
at MyAppTray.Communication.IpcFromTray.GetMyAppMode() in ...\IpcFromTray.cs:line 194
System.ObjectDisposedException
HResult=0x80131622
Message=Cannot access a disposed object.
Object name: 'System.ServiceModel.ServiceHost'.
Source=System.ServiceModel
StackTrace:
at System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrImmutable()
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open()
at MyAppTray.CustomApplicationContext.StartPipeServer() in ...\MyAppTray\CustomApplicationContext.cs:line 105
System.ServiceModel.CommunicationObjectAbortedException
HResult=0x80131501
Message=The operation 'IsAppLaunched' could not be completed because the sessionful channel timed out waiting to receive a message. To increase the timeout, either set the receiveTimeout property on the binding in your configuration file, or set the ReceiveTimeout property on the Binding directly.
Source=mscorlib
StackTrace:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at MyAppIpc.IIpcCallbackToTray.IsAppLaunched()
at MyAppTray.Communication.IpcFromTray.IsAppLaunched() in ...\MyAppTray\Communication\IpcFromTray.cs:line 142
As to my code, it basically looks like the WCF Interprocess Communication sample with changed class names, but otherwise similar, so no need placing here.
I am trying to restart after a failure, but .Close()
followed by .Open()
does not always work, as might be disposed, creating a new one gets a URI endpoint already existing. I tried many ways to get things stable to no avail.
I have time out to 10-seconds at the moment. The original time out was 1-minute, the default by Microsoft. I thought my application hung at first. Session stuff does not help the cause. I tried adding a delay, Thread.Sleep(4000), but that is annoying and does nothing. The application might be open, but, again, sleeping 4000 or 4000000000000 makes no difference whatsoever.
The bottom line is that for whatever reason I cannot stabilize the callback. Yes, the callback is static. I do not see any other way but that.
Thoughts? I am mega frustrated at the moment.