Remoting - How to raise an event on a MarshalByRef Object in C#

D

Dan Cimpoiesu

I have a remoting object, derived from MarshalByRefComponent, that I
instantiate on the client side, with Activator.GetObject.
Can I receive events fired on the server, on the client?
How?
 
D

Dan Cimpoiesu

This is the error that I get when trying to raise the event.

This remoting proxy has no channel sink which means either the server has no registered server channels that are listening, or this application has no suitable client channel to talk to the server.
Thanks Anders

But I still can't manage to make it work.
Still nothing happens on client when I raise the event from server.

Here are some snippets of my code.

//
//on server side
//
public class RemotingServer : MarshalByRefObject
{
private Int32 current;
private Int32 total;

public event PrepareProgressHandler PrepareProgress;

//this is a Zip Control event handler
protected void OnZipProgress(DartZip.ZipStatusConstants constants,DartZip.File file,
Int32 x,Int32 fileBytes,Int32 totalBytes)
{
current=totalBytes;
total=file.Size;
try
{
(new Thread(new ThreadStart(OnPrepareProgress))).Start();
}
catch
{
log.WriteLine("OnZipProgress() - Cannot start a new thread");
}
}

protected virtual void OnPrepareProgress()
{
try
{
if (PrepareProgress!=null)
{
PrepareProgress(this,new PrepareProgressArgs(current,total));
}
}
catch
{
log.WriteLine("OnPrepareProgress - Cannot raise the event");
}
}

}

public class PrepareProgressArgs : EventArgs
{
private Int64 _current;
private Int64 _total;

public Int64 Current
{
get {return _current;}
}
public Int64 Total
{
get {return _total;}
}

public PrepareProgressArgs(Int64 current,Int64 total)
{
_current=current;
_total=total;
}
}

public delegate void PrepareProgressHandler(Object source,PrepareProgressArgs args);




//
//on client side
//

srv=(RemotingServer)Activator.GetObject(typeof(RemotingServer),Settings..ServerName);
srv.PrepareProgress+=new Remoting.PrepareProgressHandler(srv_PrepareProgress);

public void srv_PrepareProgress(Object sender,PrepareProgressArgs args)
{
pbrMain.Maximum=(Int32)args.Total;
pbrMain.Value=(Int32)args.Current;
Application.DoEvents();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top