Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. busy threads

busy threads

Scheduled Pinned Locked Moved C#
designhelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pyro Joe
    wrote on last edited by
    #1

    I have a process that is executing so fast that the ui can't keep up. there is a function that is called as fast as the next file is copied from an old location to a new location. I am keeping a record of this in a textbox. however, this is happening so fast that the form surface is greyed out kinda and not showing the control's contents untill the process of copying files has completed. Worker threads shouldn't be used to manipulate ui controls, and I've tried using a timer, and I've tried delaying threading. I've had no luck. Even invalidating the control every time a new item should be painted doesn't work. I am very open to any help or suggestions. Thank you, Stephen

    P 1 Reply Last reply
    0
    • P Pyro Joe

      I have a process that is executing so fast that the ui can't keep up. there is a function that is called as fast as the next file is copied from an old location to a new location. I am keeping a record of this in a textbox. however, this is happening so fast that the form surface is greyed out kinda and not showing the control's contents untill the process of copying files has completed. Worker threads shouldn't be used to manipulate ui controls, and I've tried using a timer, and I've tried delaying threading. I've had no luck. Even invalidating the control every time a new item should be painted doesn't work. I am very open to any help or suggestions. Thank you, Stephen

      P Offline
      P Offline
      Pyro Joe
      wrote on last edited by
      #2

      problem solved. if anybody else ever has this problem, this is what I used: System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(15)); form2.Invalidate(); form2.Refresh(); System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(20));

      S D 2 Replies Last reply
      0
      • P Pyro Joe

        problem solved. if anybody else ever has this problem, this is what I used: System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(15)); form2.Invalidate(); form2.Refresh(); System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(20));

        S Offline
        S Offline
        S Senthil Kumar
        wrote on last edited by
        #3

        You do realize that you're slowing down the copying also, don't you? The best way is to have a worker thread to the copying and report progress to the UI using BeginInvoke or Invoke. See www.codeproject.com/csharp/begininvoke.asp[^] for more details. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

        1 Reply Last reply
        0
        • P Pyro Joe

          problem solved. if anybody else ever has this problem, this is what I used: System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(15)); form2.Invalidate(); form2.Refresh(); System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(20));

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          You could also replace all this code with a simple call to:

          Application.DoEvents();

          This will let the UI respond to WM_PAINT messages and update the screen. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups