Can a WinForm be a remoted object?
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.remoting.

Post a new message to this list...

Julia
Hi,

I have a server application which composed from a form which uses the Task
pattern to run background processes(threads),
each process is correctly update the user interface in the UI thread.

I want to allow ASP.NET application to call a method on my server
Since it is my first attempt I would like not to deal with synchronization
issue

1.is it possible to make the form a Server activated remoted object?
2.Will the call made in the UI thread?

Thanks in advance.

Reply to this message...
 
    
Ken Kolda
See comments inline below...

"Julia" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Yes, but perhaps not advisable. Since a Form derives MarshalByRefObject, it
can be remoted and used by a client app. If you decide to do this, what you
would need to do is marshal your form instance manually. For example, in
your form's contructor you might call:

RemotingServices.Marshal(this, "ServerForm.rem", typeof(IServerForm));

Almost certainly you don't want to compile your server form into the client
app, so you should have your form implement an interface (e.g. IServerForm)
that exposes the methods you need. Once you've done this, the clients can
use Activator.GetObject() to fetch your server form.

> 2.Will the call made in the UI thread?

Remoting calls will never be made in the UI thread, so you will always need
to marshal them using Form.Invoke() (or BeginInvoke()). This is another
reason why it's good to have a interfaces specifically for remoting. That
way you can limit the methods the client has access to so you only need to
worry about calling Invoke() in those.

I would recommend though that you not remote your actual form instance.
Instead, create another class that implements IServerForm and forwards the
calls to the main form. This would be especially important if this form may
be disposed during the lifetime of your app. That said, if your server form
will live for the entire lifetime of your server app, then it should be fine
(just remember to override InitializeLifetimeServices()).

Ken

Reply to this message...
 
 
System.Activator
System.MarshalByRefObject
System.Runtime.Remoting.RemotingServices
System.Windows.Forms.Form




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com