[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

microsoft.public.dotnet.framework.remoting

Can a WinForm be a remoted object?

Julia

9/1/2004 10:26:00 AM


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.






1 Answer

Ken Kolda

9/1/2004 4:27:00 PM

0

See comments inline below...

"Julia" <codewizard@012.net.il> wrote in message
news:OWeKq4AkEHA.3348@TK2MSFTNGP12.phx.gbl...
>
> 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?

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