First, note that it is not true that setting the variable holding the proxy
to nothing or having that variable go out of scope will disconnect the
client.
Now, if you added a client-side event handler to one of your server object's
events and you no longer wish to receive that event, then you need to either
explicitly remove that event handler, e.g.
serverObject.SomeEvent -= myEventHandler;
or your need to disconnect the object which is handling the event from the
remoting infrastructure. For example, let's say in your code somewhere you
have this:
MyObject serverObject = (MyObject) Activator.GetObject(...);
serverObject.SomeEvent += new EventHandler(this.myEventHandler);
Then to forcibly disconnect the object that acts as the event handler would
require that you call RemotingServices.Disconnect() on the object referenced
by "this" in the code above. If you do this, then the next time the server
raises the event it will attempt to invoke the delegate it's holding that
references "this.myEventHandler". However, since the event handler object
("this") has been disconnected from the remoting infrastructure on the
client, the server will get an exception ("Requested service no longer
available").
Remote events can be very tricky since an exception such as this can cause
all of your other event handlers not to be called. If you haven't done so
already, check out
http://www.dotnetjunkies.com/Tutorial/BFB598D4-0CC8-4392-893D-30252E2B3283.dcik for a discussion of how to safely code events in a remoting environment.
Ken
[quoted text, click to view] "Kivash" <emmanuel@epr.footman-walker.com> wrote in message
news:c2479047.0409170336.4f311e0e@posting.google.com...
> Hi everyone!
>
> I have this problem: After instantiating a proxy to a remote object
> using Activator.GetObject, I receive events fired by the remote object
> as expected.
>
> However, when I set the proxy to nothing, the code in the event
> handlers still executes; that is, the events still continue to be
> received?!
>
> How do I destroy the proxy? I read somewhere in this forum that when
> the proxy goes out of scope or is set to nothing, then it means the
> client is disconnected from the server.
>
> Please advise what the problem might be.
>
> Thanks,
>
> Kivash.