[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

microsoft.public.dotnet.framework.remoting

Panel update problem after remote trigger

Jan van Schalkwyk

6/16/2004 10:36:00 AM

Hi,

I first posted my problem to the WindowsForms group, but realized afterwards
my remoting object is the cause....

I have a remote trigger object that is instanced the moment my local app
starts up. I then assign a local event handler to my remote object:

eventhandler = new ScaleUIEventHandlers(); //this is a
MarshalByRefObject
eventhandler.UINotificationHandler = new VASNotification(ScaleNotify);
//point to my local event handler - see below
RemotingServices.Marshal(eventhandler, myURI);
eventhandler.RegisterInterface(ScaleVASI, typeof(ScaleUIEventHandlers));
(I hope this is a valid way to trigger a local method from a remote object?
At first I only fired the event from the remote object, but no error was
returned if the link was broken and the trigger never handled....by
accessing the method directly I get a remote exception if the local object
died...)


I simplified the ScaleNotify handler to be: (The PictureBoxe is populated,
and theparent panel is made visible) THIS PANEL1 IS INVISIBLE ON STARTUP.

public void ScaleNotify(VASNotificationArgs args)
{
pic1.Image = new Bitmap("c:\\tbmp.bmp");
panel1.Visible = true; //Visible = false initially
}

This does not work - the panel is not repainted, and the app stops
responding - if you move the form, you could see the development environment
where the panel is supposed to be....

WHAT DOES WORK:
* If I call ScaleNotify locally when I press a button it works fine.
* If panel1 is VISIBLE on startup, it works fine with the remote trigger!

Hope somebody can help me!
Jan van Schalkwyk


6 Answers

Sunny

6/16/2004 2:39:00 PM

0

Hi Jan,

as you maybe know, the windows forms are NOT thread safe, and you must
access its methods/properties only from its own UI thread.

The remoting event is fired on a different thread, so you must use
Form.Invoke (or better BeginInvoke to not block) in order to marshal the
call to UI thread. Search in this group, I have posted some examples.

Hope that helps

Sunny


In article <egLVT44UEHA.2360@TK2MSFTNGP10.phx.gbl>,
jan@leavethisout.fouriersystems.co.za says...
> Hi,
>
> I first posted my problem to the WindowsForms group, but realized afterwards
> my remoting object is the cause....
>
> I have a remote trigger object that is instanced the moment my local app
> starts up. I then assign a local event handler to my remote object:
>
> eventhandler = new ScaleUIEventHandlers(); //this is a
> MarshalByRefObject
> eventhandler.UINotificationHandler = new VASNotification(ScaleNotify);
> //point to my local event handler - see below
> RemotingServices.Marshal(eventhandler, myURI);
> eventhandler.RegisterInterface(ScaleVASI, typeof(ScaleUIEventHandlers));
> (I hope this is a valid way to trigger a local method from a remote object?
> At first I only fired the event from the remote object, but no error was
> returned if the link was broken and the trigger never handled....by
> accessing the method directly I get a remote exception if the local object
> died...)
>
>
> I simplified the ScaleNotify handler to be: (The PictureBoxe is populated,
> and theparent panel is made visible) THIS PANEL1 IS INVISIBLE ON STARTUP.
>
> public void ScaleNotify(VASNotificationArgs args)
> {
> pic1.Image = new Bitmap("c:\\tbmp.bmp");
> panel1.Visible = true; //Visible = false initially
> }
>
> This does not work - the panel is not repainted, and the app stops
> responding - if you move the form, you could see the development environment
> where the panel is supposed to be....
>
> WHAT DOES WORK:
> * If I call ScaleNotify locally when I press a button it works fine.
> * If panel1 is VISIBLE on startup, it works fine with the remote trigger!
>
> Hope somebody can help me!
> Jan van Schalkwyk
>
>
>

Jan van Schalkwyk

6/17/2004 7:48:00 AM

0

....Thanks for the reply, I did''nt use BeginInvoke, but implemented it now.
I realise it is necessary.
It did not solve my original problem though. I solved it with a
work-around. Funnily enough I get the problem only diretly after start-up-
if I make the panels invisible after the app was started, I have no problem
making them visible/invisible afterwards.... very strange indeed!


"Sunny" <sunnyask@icebergwireless.com> wrote in message
news:O8EP1%236UEHA.556@tk2msftngp13.phx.gbl...
> Hi Jan,
>
> as you maybe know, the windows forms are NOT thread safe, and you must
> access its methods/properties only from its own UI thread.
>
> The remoting event is fired on a different thread, so you must use
> Form.Invoke (or better BeginInvoke to not block) in order to marshal the
> call to UI thread. Search in this group, I have posted some examples.
>
> Hope that helps
>
> Sunny
>
>
> In article <egLVT44UEHA.2360@TK2MSFTNGP10.phx.gbl>,
> jan@leavethisout.fouriersystems.co.za says...
> > Hi,
> >
> > I first posted my problem to the WindowsForms group, but realized
afterwards
> > my remoting object is the cause....
> >
> > I have a remote trigger object that is instanced the moment my local app
> > starts up. I then assign a local event handler to my remote object:
> >
> > eventhandler = new ScaleUIEventHandlers(); //this is a
> > MarshalByRefObject
> > eventhandler.UINotificationHandler = new VASNotification(ScaleNotify);
> > //point to my local event handler - see below
> > RemotingServices.Marshal(eventhandler, myURI);
> > eventhandler.RegisterInterface(ScaleVASI, typeof(ScaleUIEventHandlers));
> > (I hope this is a valid way to trigger a local method from a remote
object?
> > At first I only fired the event from the remote object, but no error was
> > returned if the link was broken and the trigger never handled....by
> > accessing the method directly I get a remote exception if the local
object
> > died...)
> >
> >
> > I simplified the ScaleNotify handler to be: (The PictureBoxe is
populated,
> > and theparent panel is made visible) THIS PANEL1 IS INVISIBLE ON
STARTUP.
> >
> > public void ScaleNotify(VASNotificationArgs args)
> > {
> > pic1.Image = new Bitmap("c:\\tbmp.bmp");
> > panel1.Visible = true; //Visible = false
initially
> > }
> >
> > This does not work - the panel is not repainted, and the app stops
> > responding - if you move the form, you could see the development
environment
> > where the panel is supposed to be....
> >
> > WHAT DOES WORK:
> > * If I call ScaleNotify locally when I press a button it works fine.
> > * If panel1 is VISIBLE on startup, it works fine with the remote
trigger!
> >
> > Hope somebody can help me!
> > Jan van Schalkwyk
> >
> >
> >


Sunny

6/17/2004 1:59:00 PM

0

Hi Jan,
most probably it is a threading issue as well. Your handler is called in
different thread, and you can not touch safetly form''s and control''s
properties.
You have to use .Invoke for this.

Try to put this here to see if I''m right:

public void ScaleNotify(VASNotificationArgs args)
{
if (panel1.InvokeRequired)
MsgBox("Invoke required");
else
{
pic1.Image = new Bitmap("c:\\tbmp.bmp");
panel1.Visible = true; //Visible = false initially
}
}

Sunny

In article <eq3kB$DVEHA.2564@TK2MSFTNGP11.phx.gbl>,
jan@leavethisout.fouriersystems.co.za says...
> ...Thanks for the reply, I did''nt use BeginInvoke, but implemented it now.
> I realise it is necessary.
> It did not solve my original problem though. I solved it with a
> work-around. Funnily enough I get the problem only diretly after start-up-
> if I make the panels invisible after the app was started, I have no problem
> making them visible/invisible afterwards.... very strange indeed!
>
>
> "Sunny" <sunnyask@icebergwireless.com> wrote in message
> news:O8EP1%236UEHA.556@tk2msftngp13.phx.gbl...
> > Hi Jan,
> >
> > as you maybe know, the windows forms are NOT thread safe, and you must
> > access its methods/properties only from its own UI thread.
> >
> > The remoting event is fired on a different thread, so you must use
> > Form.Invoke (or better BeginInvoke to not block) in order to marshal the
> > call to UI thread. Search in this group, I have posted some examples.
> >
> > Hope that helps
> >
> > Sunny
> >
> >
> > In article <egLVT44UEHA.2360@TK2MSFTNGP10.phx.gbl>,
> > jan@leavethisout.fouriersystems.co.za says...
> > > Hi,
> > >
> > > I first posted my problem to the WindowsForms group, but realized
> afterwards
> > > my remoting object is the cause....
> > >
> > > I have a remote trigger object that is instanced the moment my local app
> > > starts up. I then assign a local event handler to my remote object:
> > >
> > > eventhandler = new ScaleUIEventHandlers(); //this is a
> > > MarshalByRefObject
> > > eventhandler.UINotificationHandler = new VASNotification(ScaleNotify);
> > > //point to my local event handler - see below
> > > RemotingServices.Marshal(eventhandler, myURI);
> > > eventhandler.RegisterInterface(ScaleVASI, typeof(ScaleUIEventHandlers));
> > > (I hope this is a valid way to trigger a local method from a remote
> object?
> > > At first I only fired the event from the remote object, but no error was
> > > returned if the link was broken and the trigger never handled....by
> > > accessing the method directly I get a remote exception if the local
> object
> > > died...)
> > >
> > >
> > > I simplified the ScaleNotify handler to be: (The PictureBoxe is
> populated,
> > > and theparent panel is made visible) THIS PANEL1 IS INVISIBLE ON
> STARTUP.
> > >
> > > public void ScaleNotify(VASNotificationArgs args)
> > > {
> > > pic1.Image = new Bitmap("c:\\tbmp.bmp");
> > > panel1.Visible = true; //Visible = false
> initially
> > > }
> > >
> > > This does not work - the panel is not repainted, and the app stops
> > > responding - if you move the form, you could see the development
> environment
> > > where the panel is supposed to be....
> > >
> > > WHAT DOES WORK:
> > > * If I call ScaleNotify locally when I press a button it works fine.
> > > * If panel1 is VISIBLE on startup, it works fine with the remote
> trigger!
> > >
> > > Hope somebody can help me!
> > > Jan van Schalkwyk
> > >
> > >
> > >
>
>
>

Jan van Schalkwyk

6/19/2004 12:31:00 PM

0

Hi Sunny!,

Yes, Invoke was required, and it solved my problem....but I''m now confused!
I''m now working through 2 delegates using 2 Invokes to actually execute my
code - One to get from the remoting object to my local object, and then
another to marshal it locally to my form''s thread? Do I understand it
correcly? I though the BeginInvoke in my remote object will marshal it to
my local form.

I appreciate your help!
Jan


"Sunny" <sunnyask@icebergwireless.com> wrote in message
news:OuyNONHVEHA.3332@tk2msftngp13.phx.gbl...
> Hi Jan,
> most probably it is a threading issue as well. Your handler is called in
> different thread, and you can not touch safetly form''s and control''s
> properties.
> You have to use .Invoke for this.
>
> Try to put this here to see if I''m right:
>
> public void ScaleNotify(VASNotificationArgs args)
> {
> if (panel1.InvokeRequired)
> MsgBox("Invoke required");
> else
> {
> pic1.Image = new Bitmap("c:\\tbmp.bmp");
> panel1.Visible = true; //Visible = false initially
> }
> }
>
> Sunny
>
> In article <eq3kB$DVEHA.2564@TK2MSFTNGP11.phx.gbl>,
> jan@leavethisout.fouriersystems.co.za says...
> > ...Thanks for the reply, I did''nt use BeginInvoke, but implemented it
now.
> > I realise it is necessary.
> > It did not solve my original problem though. I solved it with a
> > work-around. Funnily enough I get the problem only diretly after
start-up-
> > if I make the panels invisible after the app was started, I have no
problem
> > making them visible/invisible afterwards.... very strange indeed!
> >
> >
> > "Sunny" <sunnyask@icebergwireless.com> wrote in message
> > news:O8EP1%236UEHA.556@tk2msftngp13.phx.gbl...
> > > Hi Jan,
> > >
> > > as you maybe know, the windows forms are NOT thread safe, and you must
> > > access its methods/properties only from its own UI thread.
> > >
> > > The remoting event is fired on a different thread, so you must use
> > > Form.Invoke (or better BeginInvoke to not block) in order to marshal
the
> > > call to UI thread. Search in this group, I have posted some examples.
> > >
> > > Hope that helps
> > >
> > > Sunny
> > >
> > >
> > > In article <egLVT44UEHA.2360@TK2MSFTNGP10.phx.gbl>,
> > > jan@leavethisout.fouriersystems.co.za says...
> > > > Hi,
> > > >
> > > > I first posted my problem to the WindowsForms group, but realized
> > afterwards
> > > > my remoting object is the cause....
> > > >
> > > > I have a remote trigger object that is instanced the moment my local
app
> > > > starts up. I then assign a local event handler to my remote object:
> > > >
> > > > eventhandler = new ScaleUIEventHandlers(); //this is
a
> > > > MarshalByRefObject
> > > > eventhandler.UINotificationHandler = new
VASNotification(ScaleNotify);
> > > > //point to my local event handler - see below
> > > > RemotingServices.Marshal(eventhandler, myURI);
> > > > eventhandler.RegisterInterface(ScaleVASI,
typeof(ScaleUIEventHandlers));
> > > > (I hope this is a valid way to trigger a local method from a remote
> > object?
> > > > At first I only fired the event from the remote object, but no error
was
> > > > returned if the link was broken and the trigger never handled....by
> > > > accessing the method directly I get a remote exception if the local
> > object
> > > > died...)
> > > >
> > > >
> > > > I simplified the ScaleNotify handler to be: (The PictureBoxe is
> > populated,
> > > > and theparent panel is made visible) THIS PANEL1 IS INVISIBLE ON
> > STARTUP.
> > > >
> > > > public void ScaleNotify(VASNotificationArgs args)
> > > > {
> > > > pic1.Image = new Bitmap("c:\\tbmp.bmp");
> > > > panel1.Visible = true; //Visible = false
> > initially
> > > > }
> > > >
> > > > This does not work - the panel is not repainted, and the app stops
> > > > responding - if you move the form, you could see the development
> > environment
> > > > where the panel is supposed to be....
> > > >
> > > > WHAT DOES WORK:
> > > > * If I call ScaleNotify locally when I press a button it works
fine.
> > > > * If panel1 is VISIBLE on startup, it works fine with the remote
> > trigger!
> > > >
> > > > Hope somebody can help me!
> > > > Jan van Schalkwyk
> > > >
> > > >
> > > >
> >
> >
> >


Sunny

6/21/2004 2:55:00 PM

0

Hi,
BeginInvoke in your remote object just starts an asyncronous transfer of
data, thus returning immediately without blocking until the call is
processed. And BeginInvoke uses threads from the thread pool as well.

Then, when the call reaches your form app, the remoting infrastructure
places it to be executed by a thread from that app''s thread pool.

Thats how remoting works:

1. Client makes a call to the remoting object (very simplified)
- the call is serialized
- the call is send to server
- client waits to receive response from the server (any return
value or out parameters)
- client deserializes the response and updates the local
variables.

2. At server side:
- server receives the message
- deserialize it, and makes the call on a threadpool thread
- when execution is finished, gets the results, serialize them and
send them to the client


So, at client side, BeginInvoke just sends the serialized message,
without waiting for the answer, it does not control what happens at the
server side.


Hope that helps

Sunny

In article <euNF1mfVEHA.1012@TK2MSFTNGP09.phx.gbl>,
jan@leavethisout.fouriersystems.co.za says...
> Hi Sunny!,
>
> Yes, Invoke was required, and it solved my problem....but I''m now confused!
> I''m now working through 2 delegates using 2 Invokes to actually execute my
> code - One to get from the remoting object to my local object, and then
> another to marshal it locally to my form''s thread? Do I understand it
> correcly? I though the BeginInvoke in my remote object will marshal it to
> my local form.
>
> I appreciate your help!
> Jan
>
>
> "Sunny" <sunnyask@icebergwireless.com> wrote in message
> news:OuyNONHVEHA.3332@tk2msftngp13.phx.gbl...
> > Hi Jan,
> > most probably it is a threading issue as well. Your handler is called in
> > different thread, and you can not touch safetly form''s and control''s
> > properties.
> > You have to use .Invoke for this.
> >
> > Try to put this here to see if I''m right:
> >
> > public void ScaleNotify(VASNotificationArgs args)
> > {
> > if (panel1.InvokeRequired)
> > MsgBox("Invoke required");
> > else
> > {
> > pic1.Image = new Bitmap("c:\\tbmp.bmp");
> > panel1.Visible = true; //Visible = false initially
> > }
> > }
> >
> > Sunny
> >
> > In article <eq3kB$DVEHA.2564@TK2MSFTNGP11.phx.gbl>,
> > jan@leavethisout.fouriersystems.co.za says...
> > > ...Thanks for the reply, I did''nt use BeginInvoke, but implemented it
> now.
> > > I realise it is necessary.
> > > It did not solve my original problem though. I solved it with a
> > > work-around. Funnily enough I get the problem only diretly after
> start-up-
> > > if I make the panels invisible after the app was started, I have no
> problem
> > > making them visible/invisible afterwards.... very strange indeed!
> > >
> > >
> > > "Sunny" <sunnyask@icebergwireless.com> wrote in message
> > > news:O8EP1%236UEHA.556@tk2msftngp13.phx.gbl...
> > > > Hi Jan,
> > > >
> > > > as you maybe know, the windows forms are NOT thread safe, and you must
> > > > access its methods/properties only from its own UI thread.
> > > >
> > > > The remoting event is fired on a different thread, so you must use
> > > > Form.Invoke (or better BeginInvoke to not block) in order to marshal
> the
> > > > call to UI thread. Search in this group, I have posted some examples.
> > > >
> > > > Hope that helps
> > > >
> > > > Sunny
> > > >
> > > >
> > > > In article <egLVT44UEHA.2360@TK2MSFTNGP10.phx.gbl>,
> > > > jan@leavethisout.fouriersystems.co.za says...
> > > > > Hi,
> > > > >
> > > > > I first posted my problem to the WindowsForms group, but realized
> > > afterwards
> > > > > my remoting object is the cause....
> > > > >
> > > > > I have a remote trigger object that is instanced the moment my local
> app
> > > > > starts up. I then assign a local event handler to my remote object:
> > > > >
> > > > > eventhandler = new ScaleUIEventHandlers(); //this is
> a
> > > > > MarshalByRefObject
> > > > > eventhandler.UINotificationHandler = new
> VASNotification(ScaleNotify);
> > > > > //point to my local event handler - see below
> > > > > RemotingServices.Marshal(eventhandler, myURI);
> > > > > eventhandler.RegisterInterface(ScaleVASI,
> typeof(ScaleUIEventHandlers));
> > > > > (I hope this is a valid way to trigger a local method from a remote
> > > object?
> > > > > At first I only fired the event from the remote object, but no error
> was
> > > > > returned if the link was broken and the trigger never handled....by
> > > > > accessing the method directly I get a remote exception if the local
> > > object
> > > > > died...)
> > > > >
> > > > >
> > > > > I simplified the ScaleNotify handler to be: (The PictureBoxe is
> > > populated,
> > > > > and theparent panel is made visible) THIS PANEL1 IS INVISIBLE ON
> > > STARTUP.
> > > > >
> > > > > public void ScaleNotify(VASNotificationArgs args)
> > > > > {
> > > > > pic1.Image = new Bitmap("c:\\tbmp.bmp");
> > > > > panel1.Visible = true; //Visible = false
> > > initially
> > > > > }
> > > > >
> > > > > This does not work - the panel is not repainted, and the app stops
> > > > > responding - if you move the form, you could see the development
> > > environment
> > > > > where the panel is supposed to be....
> > > > >
> > > > > WHAT DOES WORK:
> > > > > * If I call ScaleNotify locally when I press a button it works
> fine.
> > > > > * If panel1 is VISIBLE on startup, it works fine with the remote
> > > trigger!
> > > > >
> > > > > Hope somebody can help me!
> > > > > Jan van Schalkwyk
> > > > >
> > > > >
> > > > >
> > >
> > >
> > >
>
>
>

Jan van Schalkwyk

6/21/2004 5:32:00 PM

0

Thanks Sunny, you helped me a lot!
Jan

"Sunny" <sunnyask@icebergwireless.com> wrote in message
news:uFxgy%235VEHA.4092@TK2MSFTNGP11.phx.gbl...
> Hi,
> BeginInvoke in your remote object just starts an asyncronous transfer of
> data, thus returning immediately without blocking until the call is
> processed. And BeginInvoke uses threads from the thread pool as well.
>
> Then, when the call reaches your form app, the remoting infrastructure
> places it to be executed by a thread from that app''s thread pool.
>
> Thats how remoting works:
>
> 1. Client makes a call to the remoting object (very simplified)
> - the call is serialized
> - the call is send to server
> - client waits to receive response from the server (any return
> value or out parameters)
> - client deserializes the response and updates the local
> variables.
>
> 2. At server side:
> - server receives the message
> - deserialize it, and makes the call on a threadpool thread
> - when execution is finished, gets the results, serialize them and
> send them to the client
>
>
> So, at client side, BeginInvoke just sends the serialized message,
> without waiting for the answer, it does not control what happens at the
> server side.
>
>
> Hope that helps
>
> Sunny
>