Board index » delphi » How do I get a comserver to not shutdown AND still host new objects

How do I get a comserver to not shutdown AND still host new objects

I have made a Com-server. When started with StartMode = smAutomation, the server will
shutdown after the last object is destroyed.
I can avoid that by assigning an  eventhandler to Comserver.OnLastRelease, and set
ShutDown to false. The server will not shut down, but it doesn't accept any new objects,
a new server will be started.
How do I get a comserver to not shutdown AND still host new objects?

 

Re:How do I get a comserver to not shutdown AND still host new objects


You probably want to use CoLockObjectExternal.  Thats a WinAPI function that
allows the COM Object to control its lifecycle, and not the connections.
Read up about it in the help files.

The COM Object would simply call CoLockObjectExternal (I think that's the
name..if it's not, its something similar) passing a true parameter.  To shut
itself down, call it again passing a false.

Ed

Quote
Ramon Huijbens <Rhuij...@capgemini.nl> wrote in message

news:37e0d10c@newsgroups...
Quote

> I have made a Com-server. When started with StartMode = smAutomation, the
server will
> shutdown after the last object is destroyed.
> I can avoid that by assigning an  eventhandler to Comserver.OnLastRelease,
and set
> ShutDown to false. The server will not shut down, but it doesn't accept
any new objects,
> a new server will be started.
> How do I get a comserver to not shutdown AND still host new objects?

Re:How do I get a comserver to not shutdown AND still host new objects


Quote
"Ed Hillmann" <e...@mincom.com> wrote:
>You probably want to use CoLockObjectExternal

Thanx a million Ed,

I think what you meant is OleLockRunning. I am now going to look intoo that.

BTW, I have also posted this question at www.experst-exchange.com, if this works your
eligable for 100 expert-exchange points.
You would have to be registered as an expert in order to be able to receive the points
though.
I'll keep the question on for a few weeks, give you a chance to post the answer  and
cash in the points.

Greatings, Ramon

Re:How do I get a comserver to not shutdown AND still host new objects


Quote
Ramon Huijbens <Rhuij...@capgemini.nl> wrote in message

news:37e0d10c@newsgroups...
[Non-interrogative text elided.]

Quote
> How do I get a comserver to not shutdown AND still host new objects?

Ramon,

If you're using Delphi 4 (this might well be the case in Delphi 5, as well),
and you are running the server on a system that supports DCOM (and thus
support the pair of COM APIs, CoAddRefServerProccess and
CoReleaseServerProcess) then there is one more thing you must do.

In that new event handler that you assign to ComServer.OnLastRelease, after
setting ShutDown to False, call CoResumeClassObjects.  This will let the SCM
know that your server is ready to start serving objects again.

One small nit.  This won't stop another server from being started in that
fraction of time between the last call to CoReleaseServerProcess and your
call to CoResumeClassObjects.  This window of time might be microscopic and
may not matter unless you're serving up objects in bursts of thousands or
more.

Roland Bouchereau

Other Threads