[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

Proper way to destroy a remoting server

gaetan

7/8/2004 4:23:00 PM

Hello

I'm using a Remoting server (Singleton) and i would like to controle
its destruction.
Is there a kind of RemotingConfiguration.Disconfigure?
And most important : Is there a way to call a function before
disconnection?
I mean, within the Dispatcher remoting thread, i create other threads
to delegate the jobs that arrives throught Remoting. But, when I close
the application (for the moment juste a little executable), the thread
are not destroyed ! I just need a way to call Stop() for each thread
but i can't find a way ! Since it's a singleton, i cannot have a
pointer (scuse me, a reference) to the Remoting object, to be able to
call a method that will call all the Stop...
I tryed with the "destructor", but it is called ONLY if all other
thread are destroyed, so i can't use it to destroy them...

Any idea?

And by the way, how can i set a name to the remoting threads (Client
and Server) without putting it in every function? For the server, i
put
Thread.CurrentThread.Name = "jjdjd"
in the constructor, which is called at the first connexion, but for
the client, i don't find any way to do this properly...

thanks

Gaetan
6 Answers

Sunny

7/8/2004 5:09:00 PM

0

Hi, please read inline:


In article <9712e9c6.0407080822.611ca266@posting.google.com>,
gaetan@xeberon.net says...
> Hello
>
> I''m using a Remoting server (Singleton) and i would like to controle
> its destruction.
> Is there a kind of RemotingConfiguration.Disconfigure?

Why you need this? If you just unregister the channels it will be
enough.

> And most important : Is there a way to call a function before
> disconnection?
> I mean, within the Dispatcher remoting thread, i create other threads
> to delegate the jobs that arrives throught Remoting. But, when I close
> the application (for the moment juste a little executable), the thread
> are not destroyed !

Make your threads Background. Set thread.IsBackground = true; just
before you invoke thread.Start().

> I just need a way to call Stop() for each thread
> but i can''t find a way !

Do you need to make some cleanup on thread end, or you just want it to
die?

> Since it''s a singleton, i cannot have a
> pointer (scuse me, a reference) to the Remoting object, to be able to
> call a method that will call all the Stop...
> I tryed with the "destructor", but it is called ONLY if all other
> thread are destroyed, so i can''t use it to destroy them...
>
> Any idea?
>
> And by the way, how can i set a name to the remoting threads (Client
> and Server) without putting it in every function? For the server, i
> put
> Thread.CurrentThread.Name = "jjdjd"
> in the constructor, which is called at the first connexion, but for
> the client, i don''t find any way to do this properly...

If you create your own threads, you can name them. Remoting uses threads
from the thread pool, so I''m not sure what are you after.

Cheers
Sunny

Gaetan semet

7/8/2004 5:26:00 PM

0



> Why you need this? If you just unregister the channels it > will be
enough.

How can i unregister server channels ?
and client ?

> Do you need to make some cleanup on thread end, or you
> just want it to die?
Yes i have a method to call to kill them properly (with a timeout before
slaughter them...)

> If you create your own threads, you can name them.
> Remoting uses threads from the thread pool,
> so I''m not sure what are you after.
ok i understand why i can''t name them... damned.

Thank you

Gaetan


*** Sent via Devdex http://www.... ***
Don''t just participate in USENET...get rewarded for it!

Sunny

7/8/2004 7:02:00 PM

0

Hi,


In article <eDzzeCRZEHA.3144@TK2MSFTNGP12.phx.gbl>, gaetan@xeberon.net
says...
>
> How can i unregister server channels ?
> and client ?
ChannelServices.UnregisterChannel Method


> Yes i have a method to call to kill them properly (with a timeout before
> slaughter them...)

Use Application.ApplicationExit or Application.ThreadExit events to
handle the application shutdown. In the event handler stop the threads
and make any other proper cleanup.
From docs:
<cite>
You must attach the event handlers to the Exit event to perform
unhandled, required tasks before the application stops running. You can
close files opened by this application, or dispose of objects that
garbage collection did not reclaim.
</cite>

Sunny

Gaetan semet

7/9/2004 10:01:00 AM

0

Ok thanks but i still have some problems:
- ChannelServices.UnregisterChannel wants a IChannel but i don''t have it
(i configure the remoting system from a config file:)
<system.runtime.remoting>
<application name="Appname">
<service>
<wellknown displayName="Remoting" mode="Singleton"
type="Appname.ServerProcess, Appname.Server" objectUri="Server" />
</service>
<channels>
<channel port="8000" ref="tcp">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
So how can i get the channel.
I tryed ChannelServices.GetChannel but i can''t find the good name...

2) My second problem is more important:
Is it not possible to be able to avoid usign
application.ApplicationExit.. i would like not to use the
system.windows.form namespace since it''s not a Form windows and i want
to be portable (on mono with no system.windows.form for instance). It
will become a Windows Service or even a WebService so i don''t think
Application is a good class to use in this case..


No i would like to find a proper way to destroy everything FROM the
MarshalByRefObject (just calling a Detroy method).
What i can do is (not beautiful but the only thing i''ve found this far):
- have a "global" static reference to the MarshalByRefObject object
since it''s a singleton (this reference will be initilised to "this" in
all remoting exposed function just to be sure at the end i will have
this damned reference).
- At the end of the application i call a static method that will use the
static reference to call a method like Destroy() or anything that will
ends all threads and performs all cleanup.

I don''t think it''s a "proper" way do you think these is a better way to
call custom-cleanup methods ?

Thanks

*** Sent via Devdex http://www.... ***
Don''t just participate in USENET...get rewarded for it!

Sunny

7/9/2004 2:36:00 PM

0

Hi,

In article <#jyPVuZZEHA.2016@TK2MSFTNGP09.phx.gbl>, gaetan@xeberon.net
says...
<snip>
> So how can i get the channel.
> I tryed ChannelServices.GetChannel but i can''t find the good name...

ChannelServices.RegisteredChannels

>
> 2) My second problem is more important:
> Is it not possible to be able to avoid usign
> application.ApplicationExit.. i would like not to use the
> system.windows.form namespace since it''s not a Form windows and i want
> to be portable (on mono with no system.windows.form for instance). It
> will become a Windows Service or even a WebService so i don''t think
> Application is a good class to use in this case..
In case of windows service, the service exposes a OnShutdown or whatever
the method is called. So you cleanup there.
About mono/linux daemons, I have started a thread on gotmono some time
ago, but so far no answers. I have found in the archive of the dev
mailing list some discussions about service hosting, but the archive
server not function properly, so it can not display the body of any
post, just the titles. I''m waiting for them to fix it. But for sure
there should be some on shutdown method in which you can cleanup.
You know how to deal with winforms, so the only problematic part is if
your object is hosted in a console application, I realy do not know how
to capture its shutdown.

>
>
> No i would like to find a proper way to destroy everything FROM the
> MarshalByRefObject (just calling a Detroy method).
> What i can do is (not beautiful but the only thing i''ve found this far):
> - have a "global" static reference to the MarshalByRefObject object
> since it''s a singleton (this reference will be initilised to "this" in
> all remoting exposed function just to be sure at the end i will have
> this damned reference).

Yes, you can do this just creating the object, and then exposing it to
remoting with RemotingServices.Marshal.

> - At the end of the application i call a static method that will use the
> static reference to call a method like Destroy() or anything that will
> ends all threads and performs all cleanup.

That is what I would do.

>
> I don''t think it''s a "proper" way do you think these is a better way to
> call custom-cleanup methods ?

Why not? You capture the sutdown, you clean after you :)


Cheers
Sunny

Gaetan semet

7/9/2004 3:34:00 PM

0


Ok thanks i''ve managed witht the static reference ( a little ugly but it
works)!

Thank you very much for your help...


-----
Great A''Tan - http://www.xeberon....

*** Sent via Devdex http://www.... ***
Don''t just participate in USENET...get rewarded for it!