Re: Updating controls on a form

Vince P <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <004c01c76f44$e58d4b10$b0a7e130$@net>
What does the name of the control matter?  And what does it matter which
specific control is passed... all the controls are to be running on the same
thread, so one control is  as good as any other.. all you want to do is
marshal to that thread.


-
THESE are the times that try men's souls. The summer soldier and the
sunshine patriot will, in this crisis, shrink from the service of their
country; but he that stands by it now, deserves the love and thanks of man
and woman. Tyranny, like hell, is not easily conquered; yet we have this
consolation with us, that the harder the conflict, the more glorious the
triumph.

> -----Original Message-----
> From: Discussion forum for developers using Windows Forms to build apps
> and controls [mailto:[email protected]] On Behalf Of
> Kelly Baker
> Sent: Sunday, March 25, 2007 18:25
> To: [email protected]
> Subject: Re: [DOTNET-WINFORMS] Updating controls on a form
>
> No, because I cannot predict what future users of this dll will name
> their
> controls.  Right not I just have 12 variables (private shared) exposed
> through read-only properties. I raise the NewData event when I have
> updated
> the variables, and the executable responds by reading the properties.
> I
> have even tried reading the properties into variables in the Windows
> exe,
> but when I try to update the Windows controls from these variables, I
> still
> get the cross-thread error.
>
> -----Original Message-----
> From: Discussion forum for developers using Windows Forms to build apps
> and
> controls [mailto:[email protected]] On Behalf Of
> Vince P
> Sent: Saturday, March 24, 2007 11:27 PM
> To: [email protected]
> Subject: Re: [DOTNET-WINFORMS] Updating controls on a form
>
> In your DLL, can you make a member to store the Control object that is
> using
> it?
>
>
>     public  class DllClass
>     {
>         private System.Windows.Forms.Control control;
>
>         public DllClass(Control control)
>         {
>             this.control = control;
>         }
>
>         private  void CallFromOtherThread()
>         {
>             if(control.InvokeRequired)
>             {
>                 control.BeginInvoke(new
> MethodInvoker(this.CallFromOtherThread), null);
>             }
>             else
>             {
>                 // your code here
>             }
>
>         }
>     }
>
> -
> THESE are the times that try men's souls. The summer soldier and the
> sunshine patriot will, in this crisis, shrink from the service of their
> country; but he that stands by it now, deserves the love and thanks of
> man
> and woman. Tyranny, like hell, is not easily conquered; yet we have
> this
> consolation with us, that the harder the conflict, the more glorious
> the
> triumph.
>
> > -----Original Message-----
> > From: Discussion forum for developers using Windows Forms to build
> apps
> > and controls [mailto:[email protected]] On Behalf
> Of
> > Kelly Baker
> > Sent: Saturday, March 24, 2007 21:37
> > To: [email protected]
> > Subject: [DOTNET-WINFORMS] Updating controls on a form
> >
> > Unless my app is EXTREMELY simple, I get the cross-threading error
> > message
> > regularly when updating controls on a Windows form.
> >
> > My latest example involves a dll that runs a System.Threading.Timer,
> > updating private shared variables.  When it finishes updating, it
> > raises a
> > NewData event.  My app responds to that event by updating display
> > controls
> > (labels in this case).  I have to use a delegate and update them like
> > this:
> >
> > Private Sub SetText(ByVal [text] as String)
> >     If Me.Messages.InvokeRequired Then
> >         Dim d as New SetTextCallBack(AddressOf SetText)
> >         Me.Invoke(d, New Object() {[text]})
> >     Else
> >         Me.Messages.Text = [text]
> >     End If
> > End Sub
> >
> > I have to write a different routine like this for each control on the
> > form
> > that I want to update.  Is there a better way?  Please?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.