libor

I have a program that instantiates a remotable singleton object for both local access (Ipc) and Tcp in the Main: This object must exist in one instance because it gets updated with data from the serial port, which data I have to access from front-end clients running on the same computer (Ipc) and also from clients accessing it thru the net (Tcp)

I have made this override to make my object exist in one instance only and live forever:

public override Object InitializeLifetimeService() { return null; }

I am instantiating my object this way in the Main:

MyClass remobj = new MyClass();

IpcServerChannel serverChannel = new IpcServerChannel("remote");

TcpChannel chan = new TcpChannel(8084);

ChannelServices.RegisterChannel(chan, false);

RemotingServices.Marshal(remobj, "remobj");

It works OK.

But I have a minor problem: When I exit the program, my object continues to live as a process, even if no front-end clients are connected. I understand that I told it to do so, but I can't run the program a second time because of this object still alive, it exits with an error message. I have to kill the process manually in the Task Manager to be able to run my program again.

How can I kill my forever-living object upon exiting the program it is instantiated in

PS. Timeouts are not good for me, I want my object to live even if no clients are ever connected, or disconnected a long time ago (because it also logs the gathered data to a database)

Or should I make a dummy client in my Main to keep it alive while the Main runs



Re: .NET Remoting and Runtime Serialization How to kill a forever-living remote object

Sowmy Srinivasan

Can you please clarify what you mean by " When I exit the program, my object continues to live as a process..."

By Program do you mean all the client apps

It would be great if you could show when you want your server object to die (From your PS it appears you want to close if want the server to run even when no clients are running)

Thanks

Sowmy






Re: .NET Remoting and Runtime Serialization How to kill a forever-living remote object

libor

By exiting the program I mean when I close my back-end, server program (the one instantiating the object) , not the clients. I will later want to make a Windows Service running silently in the backgrund out of it, but during development (to debug it easier) it is a normal windows forms application now.

During normal usage I want my server object to never die, but occasionally I still want to be able to stop the service (close the program) and restart it (e.g. to load new configuration parameters from an xml file at startup, or whatever...). and also during the development phase I would like to be able to run it again and again after adding/modifying some code and rebuilding it.

But now I see my server program still running in the Task Manager's processes list, even after closing it. Fortunately I can kill it there manually before each restart.

if I don't do it, my program gives 'Failed to create an IPC Port: Access is denied.' error at this line:

IpcServerChannel serverChannel = new IpcServerChannel("remote");

(it can't make a new ipc channel over the existing, still living one, of course)




Re: .NET Remoting and Runtime Serialization How to kill a forever-living remote object

Sowmy Srinivasan

I see. I am not sure if the infinite timeout is what is keeping your process. Can get the stack dump of all your threads in the process

Thanks

Sowmy






Re: .NET Remoting and Runtime Serialization How to kill a forever-living remote object

libor

Thank you for pushing me in the right direction. It seems that this issue has nothing to do with the server object's lifespan.

I am starting a (deliberately) endless loop (used for periodically checking a message queue) as a new thread in the remote object. I have to stop all running threads explicitly before exiting the program.