This message was discovered on microsoft.public.dotnet.languages.csharp.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| Mark |
What I want to do is call a function in my main form/class from the server (which the another program/client calls). The main form does not really create a server object so I can't pass the frmForm class into the constructor of MyServer (the client side would have no idea what to pass into that anyways). What other way to do this is there? I guess there is static functions, but I can't make everything in those functions static.
namespace Mark { public class frmForm : System.Windows.Forms.Form { private void frmForm_Load(object sender, System.EventArgs e) { HttpChannel channel = new HttpChannel(8001); //Create a new channel ChannelServices.RegisterChannel (channel); //Register channel RemotingConfiguration.RegisterWellKnownServiceType(typeof (MyServer),"MyServer",WellKnownObjectMode.Singleton); } public void Function1() { //do some non-static stuff here } }
public class MyServer: MarshalByRefObject { public void CalledByClient() { //want to call frmForm.Function1 here } } }
|
|
| |
| |
| Richard Blewett |
Well MyServer is a singleton how about getting the form to achieve the same effect by manually marshallingobject into the remoting infrastructure.
instead of using RegisterWellKnownServicetype, create an instance of MyServer pass itself into the ctor and then call RemotingServices.Marshal passing the instance.
Its proably a good idea in this case to override InitializeLifetimeServices in MyServer and return null. This will disable the lease based distributed garbage collection of remoting which in this case is probably a good idea.
Regards
Richard Blewett - DevelopMentor http://staff.develop.com/richardb/weblog
"Mark" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
|
|
| |
| |
| Mark |
"Richard Blewett" <Click here to reveal e-mail address> wrote in message news:<Click here to reveal e-mail address>... [Original message clipped]
So would I do something like?
MyServer svr = new MyServer(); svr.PassFormOver(this); ObjRef objrefWellKnown = RemotingServices.Marshal(svr, ???????);
What do I put for the other arguments?
I would of course put something like
public class MyServer: MarshalByRefObject { static public Mark.frmForm frmMyForm;
public void PassFormOver(Mark.frmForm frm) { frmMyForm = frm; }
public void CalledByClient() { //want to call frmForm.Function1 here } } }
|
|
| |
| | |
|
|
|
|
|
|