G
Guest
Hello,
Basically, I want my application to run only one instance at a time and pass
command line arguments to a running instance. I have all of this working, I
used the IPC Remoting channel and my program handles the command line
arguments well. However, after my program has been running for a little while
(say 5-10 minutes) the command line arguments no longer are passed, and
instead it causes a .NET Remoting exception claiming to have come across a
null reference.
So in my Program.cs file, I have something like this.
if (alreadyrunning)
{
IpcChannel ipcCh = new IpcChannel("MyProgram_" + username);
ChannelServices.RegisterChannel(ipcCh, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotingService),
"Remoting", WellKnownObjectMode.Singleton);
ISharedAssemblyInterface obj = (ISharedAssemblyInterface)
Activator.GetObject(typeof(ISharedAssemblyInterface),
"ipc://MyProgram_" + username + "/Remoting");
obj.RunFirstInstance(arguments);
}
else
{
ISharedAssemblyInterface obj = (ISharedAssemblyInterface)
Activator.GetObject(typeof(ISharedAssemblyInterface),
"ipc://MyProgram_" + username + "/Remoting");
obj.HandleCommandLineArgs(arguments);
}
Again, it all works for a short time, but stops working claiming a null
reference on the HandleCommandLineArgs method after a while. I'm guessing
that even though I specifify a Singleton instance that it somehow gets
garbage collected or a new RemotingService class generated (even though my
program is still running).
Thanks in advance,
mitch
p.s. Sorry if this is a double post, I think my last one went into a thread,
instead of starting it's own topic.
Basically, I want my application to run only one instance at a time and pass
command line arguments to a running instance. I have all of this working, I
used the IPC Remoting channel and my program handles the command line
arguments well. However, after my program has been running for a little while
(say 5-10 minutes) the command line arguments no longer are passed, and
instead it causes a .NET Remoting exception claiming to have come across a
null reference.
So in my Program.cs file, I have something like this.
if (alreadyrunning)
{
IpcChannel ipcCh = new IpcChannel("MyProgram_" + username);
ChannelServices.RegisterChannel(ipcCh, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotingService),
"Remoting", WellKnownObjectMode.Singleton);
ISharedAssemblyInterface obj = (ISharedAssemblyInterface)
Activator.GetObject(typeof(ISharedAssemblyInterface),
"ipc://MyProgram_" + username + "/Remoting");
obj.RunFirstInstance(arguments);
}
else
{
ISharedAssemblyInterface obj = (ISharedAssemblyInterface)
Activator.GetObject(typeof(ISharedAssemblyInterface),
"ipc://MyProgram_" + username + "/Remoting");
obj.HandleCommandLineArgs(arguments);
}
Again, it all works for a short time, but stops working claiming a null
reference on the HandleCommandLineArgs method after a while. I'm guessing
that even though I specifify a Singleton instance that it somehow gets
garbage collected or a new RemotingService class generated (even though my
program is still running).
Thanks in advance,
mitch
p.s. Sorry if this is a double post, I think my last one went into a thread,
instead of starting it's own topic.