[VB, C#]Updating a UI element

Discussion in 'Mixed Languages' started by QuantumBug, May 7, 2015.

  1. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,527
    1,381
    60
    #1 QuantumBug, May 7, 2015
    Last edited: May 7, 2015
    Seems Thread.Sleep(integer) is causing high CPU load, 15% +/=...

    What way do other developers update UI elements automatically? If you care to share that would be great.

    Regards, David.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Michaela Joy

    Michaela Joy MDL Crazy Lady

    Jul 26, 2012
    3,715
    4,048
    120
    I found this. http://stackoverflow.com/questions/3886171/why-thread-sleep-is-so-cpu-intensive

    and this https://social.msdn.microsoft.com/F...78/sleep-loop-causes-high-cpu?forum=vbgeneral
    Oh, and I don't know if you saw this http://blogs.msmvps.com/peterritchie/2007/04/26/thread-sleep-is-a-sign-of-a-poorly-designed-program/

    And this http://www.codeproject.com/Questions/175229/Threading-and-CPU-usage

    I don't use VB or C#, but I have done threaded programming with Delphi. It's tricky. Usually, the UI is controlled in the main thread, and the worker thread gives the main thread a slice of time, to update the UI. (i.e. respond to "cancel" button or move a progress bar)

    Hope this helps a little...

    :MJ
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,906
    20,437
    180
    Would be easier to give an answer if you gave what it is your updating.. I would maybe use an invoke new delegate or even SynchronizationContext :eek:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,527
    1,381
    60
    It's processor usage and memory usage, Alpha :)

    And MJ: Thanks for the resources. I did read the one about thread.sleep.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...