RE: System Timer Puzzle



Hi Robert,
the System.Timer.Timer executes the code from a thread inside the
ThreadPool. You should only ever change a controls property using the thread
that created the control, this is not happening in your case, which could be
causing your problem.

If you want to get around this then you can either use a
System.Windows.Forms.Timer which executes inside the main UI thread - but can
be problematic if you are doing lots of processing, or you can stick with the
Timers.Timer and call Invoke or BeginInvoke on the user control, passing in a
delegate to be executed, thiswill then be executed by the thread that created
the control.

For a more detailed explanation see:
http://www.yoda.arachsys.com/csharp/threads/winforms.shtml

Hope that helps
Mark R Dawson

"Robert W." wrote:

> I'm building a WinForms app that is a companion to a Pocket PC app. The
> WinForms app initiates a separate thread that calls a Notification window.
> This window resides in the lower right corner of the screen and keeps the
> user informed about what is happening during data transfer to/from the Pocket
> PC.
>
> Everything has been working fine with the Notification window until now.
> Here's the problem:
>
> I'm using RAPI to copy the required CAB files to the Pocket PC. Some of
> them are quite large, up to 2.5MB in size. During the copying, I wanted to
> keep the user informed about the progress. So I instaniated a System Timer
> in the Notification form that executes an event every second. One of the
> thing the Interval Handler of this timer does is call the RAPI object to find
> out the current filesize on the Pocket PC (ie. how many bytes have been
> copied so far).
>
> When writing this information to the Debug window, it seems to work
> basically okay. But when I try to display it in a label on the Notification
> form, it just does not. I tried adding "this.Refresh()" and
> "Application.DoEvents()" after setting the label but this did not resolve the
> problem.
>
> Any idea why not and how I can solve the problem?
>
> --
> Robert W.
> Vancouver, BC
> www.mwtech.com
>
.



Relevant Pages

  • RE: System Timer Puzzle
    ... > that created the control, this is not happening in your case, which could be ... > System.Windows.Forms.Timer which executes inside the main UI thread - but can ... >> I'm building a WinForms app that is a companion to a Pocket PC app. ... >> WinForms app initiates a separate thread that calls a Notification window. ...
    (microsoft.public.dotnet.languages.csharp)
  • Add Webpart to MySite from a own control
    ... I created a custom control that is embedded on the MySite private view ... The control just executes some code, ... Updates are currently disallowed on GET requests. ...
    (microsoft.public.sharepoint.portalserver.development)
  • Prevent a record being saved after an error occurs
    ... "cmdSaveRecord" sub which, amongst other things, executes this command: ... Within here, some validation is ... If the control fails ... Cancel = True ...
    (microsoft.public.access.formscoding)
  • Re: mouseover function for text objects?
    ... code in that sample that he posted set up the code that executes when you ... gives it the string "Hello World!" ... quotes) and will cause the message "The mouse is over this control" (again ...
    (comp.soft-sys.matlab)