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. Painting issue while running two different threads

Painting issue while running two different threads

Scheduled Pinned Locked Moved C#
helpdesignquestion
3 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
    Piyush Vaishnav
    wrote on last edited by
    #1

    Hi, I am having one form with yes and no button running in one thread. And one worker thread is running which will keep repeating it's task at every 4 sec. While worker thread is running, and if i will click yes in other threads, program takes lot of time to execute the action to be performed by clicking yes button. Because of this background of Main UI is not painted for that much of time period. How I can solve this problem? Atleast background of Main UI should be repainted all the time. Thanks in Advance..

    D B 2 Replies Last reply
    0
    • P Piyush Vaishnav

      Hi, I am having one form with yes and no button running in one thread. And one worker thread is running which will keep repeating it's task at every 4 sec. While worker thread is running, and if i will click yes in other threads, program takes lot of time to execute the action to be performed by clicking yes button. Because of this background of Main UI is not painted for that much of time period. How I can solve this problem? Atleast background of Main UI should be repainted all the time. Thanks in Advance..

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

      It sounds as if you've done something very wrong. The form should be on the UI (startup) thread and your worker code on the background thread. If the background isn't doing actual work, it shouldn't normally be running at all, unless this is some kind of server process. It really depends on what you're doing, but it's customary to create the worker background object when needed and let it terminate itself when the work is done, though, that's not always possible or appropriate. The other popular method is to run the background thread in two modes, work and polling. Work mode is obvious. This is where the thread is actually processing work. Polling mode is where the thread is checking some kind of variable every so often to see if there's work to be picked up and processed. This polling should be done in a loop that is delayed with a sleep for, say, once a second. The UI code, your Yes button code, should set the variable appropriately to get the background thread to kick off work.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      1 Reply Last reply
      0
      • P Piyush Vaishnav

        Hi, I am having one form with yes and no button running in one thread. And one worker thread is running which will keep repeating it's task at every 4 sec. While worker thread is running, and if i will click yes in other threads, program takes lot of time to execute the action to be performed by clicking yes button. Because of this background of Main UI is not painted for that much of time period. How I can solve this problem? Atleast background of Main UI should be repainted all the time. Thanks in Advance..

        B Offline
        B Offline
        BobJanova
        wrote on last edited by
        #3

        The action that takes a long time should not be in the main UI thread; instead, that's what should be farmed out to a worker thread or a Task.

        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