Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Remoting / September 2004

Tip: Looking for answers? Try searching our database.

Remoting and Events

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrick Jox - 29 Sep 2004 11:05 GMT
Hi,
I have some problems with eventhandlers, that update some gui elements. I
have implemented an eventwrapper class, that exposes an event handler which
is registered to the server.event. This eventhandler then fires another
event to which a gui method is registered. As long as I am using tcp, my gui
hangs. I tried around with several ideas but I always had the same result. I
got an example that did exactly the same as my application and it worked
fine ther. The only difference was, that I was using tcp and the example was
using http.

So in a moment of crazyness i switched my application to http and since than
it worked.

Can anybody explain this behavior?

I thought, that the protocoll should not influence my implementation so
deep?

Any Ideas?

Thanks - Patrick
Ken Kolda - 29 Sep 2004 17:03 GMT
The most likely source of your problem is that you're not using the
Form.Invoke() method to marshal the call to your UI thread before changing
your GUI. The callback into your client will never occur on the UI thread,
so these calls should never directly modify UI elements in a form. Even if
this seems to work for HTTP, you still need to use Form.Invoke() -- that's
the only guaranteed safe method.

Ken

> Hi,
> I have some problems with eventhandlers, that update some gui elements. I
[quoted text clipped - 17 lines]
>
> Thanks - Patrick
Patrick Jox - 30 Sep 2004 05:53 GMT
Hi Ken,
thanks again for trying to help me. The application where I am working
around is still the same.

I tried to do the following with tcp.

I wrote an eventhandler, named eventwrapper. He was instanced by the form by
passing the form itself and a forms delegate to the constructor.
The eventhandler provided an event procedure. This procedure was registered
to listening events of my server. When the event occured he executed
something like form.Invoke(formsDelegate).

But as soon as the delegate tried to modify GUI elements. The application
hang?

What is wrong with that. Do you know an example for managing this.

Thanks - Patrick

> The most likely source of your problem is that you're not using the
> Form.Invoke() method to marshal the call to your UI thread before changing
[quoted text clipped - 31 lines]
> >
> > Thanks - Patrick
Ryan  Berry - 30 Sep 2004 15:08 GMT
Patrick,

I'm not sure I follow what you tried to do with "tcp".  What Ken is
saying is that you should not modify GUI elements from any other thread
than the main GUI thread; thus, you need to use form.invoke.  Here's an
example:  (I used 2 parameters to show how to use the object array)

Delegate Definition:
private delegate void EventCompleteCB(string Message,in Value);

Event Delegate:  (IE: Method that is calledback on when the event is
raised)
private void EventComplete(string Message, int Value)
{
Object[] param = {Message,Value};
this.Invoke(new EventCompleteCB(InternalEventComplete),param);
}

Internal Form GUI Update Method:
private void InternalEventComplete(string Message, int Value)
{
// Only update GUI elements here
[formControl].Text = Message;
}

Hope this helps.

          -- Ryan Berry
Ken Kolda - 30 Sep 2004 16:19 GMT
That certainly sounds reasonable -- if your wrapper is calling Form.Invoke()
then you should be good. If you can post a very simple project that
demonstrates this problem, that might be helpful.

Ken

> Hi Ken,
> thanks again for trying to help me. The application where I am working
[quoted text clipped - 52 lines]
> > >
> > > Thanks - Patrick

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.