RE: cross-thread update requests

"Greg Hewgill" <[email protected]> Tue, 17 May 2005 16:27:12 -0500
Newsgroups gmane.comp.lib.wxwindows.wxnet
Message-ID <[email protected]>
I understand in principle what you mean here, but I can't seem to find
the right way to do this in practice. In my constructor:

	UpdateId = UniqueID;
	wx.Event.AddEventType(UpdateId, typeof(wx.CommandEvent));
	AddEventListener(UpdateId, new wx.EventListener(OnUpdate));

and when I want to send the event:

	wx.CommandEvent u = new wx.CommandEvent();
	u.Int = UpdateId;
	AddPendingEvent(u);

Now, the code as above won't compile because wx.CommandEvent does not
have a constructor that takes zero parameters. So I try to call
wx.CommandEvent((IntPtr)null) but I'm sure that's not doing what I want
because I get a "Unable to create instance of wx.CommandEvent"
exception.

Furthermore, if I ignore the AddPendingEvent code and just try to run
the constructor, I get an exception from wx.Event.AddEventType, that the
value returned from UniqueID (which happens to be 10014) is already in
some hashtable. I concluded that the value returned from UniqueID is not
really very unique, and just picked an unused number myself that avoided
that exception. What is the scope in which UniqueID actually returns a
unique value?

Anyway, is my event type declaration correct? If so, then there must be
a better way to call AddPendingEvent that doesn't involve three
statements. Do I need to create a derived event class here? If so, how
do I call the base constructor?

I also can't seem to find the EVT_CUSTOM handler from wxWidgets anywhere
in wx.NET. Might that be what I want?

Greg Hewgill

-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Robert
Roebling
Sent: Thursday, May 12, 2005 19:04
To: wxNET
Subject: Re: [Wxnet-users] cross-thread update requests


nummish wrote:

> this.EventHandler.AddPendingEvent(new UpdateUIEvent(_GuiUiId));
> where _GuiUiId is assigned in the constructor by calling
this.UniqueID();

The wxUpdateUI event is not the right event for calling
Refresh() on some window. Just send a command event with
a new event type to the window to be refreshed and catch
the event there.

  Robert

> 
> 
> On 5/12/05, Greg Hewgill <[email protected]> wrote:
> >  
> > 
> > I'm writing an application that has a GUI and needs to have a
separate
> > network communications thread (the network communications will often
block
> > so it's not appropriate to do the network stuff in the UI thread).
What I
> > need to do is send some kind of request to the associated GUI window
to
> > update the display when new information is retrieved from the
network. I was
> > calling Refresh() on the associated Window object, but that seems to
be
> > causing lockups and crashes. It looks like I need to use
AddPendingEvent()
> > but I'm not sure what kind of event is appropriate for this type of
thing,
> > or whether such an event type already exists. 
> > 
> > What's the usual way of doing this? 
> > 
> > Greg Hewgill 
> > 
>
smime.p7s (application/x-pkcs7-signature, 2.8 KB) - not displayed