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. how to restart the thread

how to restart the thread

Scheduled Pinned Locked Moved C#
sysadmintutorial
6 Posts 4 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.
  • R Offline
    R Offline
    renuga5298
    wrote on last edited by
    #1

    Hi, I am using threading concept in my application to fetch the image form the video server and display. the code is: for (int i = 0; i < dataCount; i++) { doneEvents[i] = new ManualResetEvent(false); ImageReader imgr = new ImageReader(doneEvents[i]); objImageReader[i] = imgr; WaitCallback callback = delegate(object state) { imgr.DownloadFile((structCameraServer)state); }; ThreadPool.QueueUserWorkItem(callback, objServer[i]); } WaitHandle.WaitAll(doneEvents); but how to call the thread again after completion of the work (ie how to make the thread to start again). Thanks in advance,

    L N 2 Replies Last reply
    0
    • R renuga5298

      Hi, I am using threading concept in my application to fetch the image form the video server and display. the code is: for (int i = 0; i < dataCount; i++) { doneEvents[i] = new ManualResetEvent(false); ImageReader imgr = new ImageReader(doneEvents[i]); objImageReader[i] = imgr; WaitCallback callback = delegate(object state) { imgr.DownloadFile((structCameraServer)state); }; ThreadPool.QueueUserWorkItem(callback, objServer[i]); } WaitHandle.WaitAll(doneEvents); but how to call the thread again after completion of the work (ie how to make the thread to start again). Thanks in advance,

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      renuga5298 wrote:

      how to make the thread to start again

      new Thread( ... )

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 beta 1 - out now!
      ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

      R 1 Reply Last reply
      0
      • L leppie

        renuga5298 wrote:

        how to make the thread to start again

        new Thread( ... )

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 beta 1 - out now!
        ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

        R Offline
        R Offline
        renuga5298
        wrote on last edited by
        #3

        assume like i have 10 threads intially, if i am restarting again with the new thread(...) wont the thread count be increased to 20 and when the number of the thread increases it may create probelm as i need to do this functionality for every 1 sec time interval.

        1 Reply Last reply
        0
        • R renuga5298

          Hi, I am using threading concept in my application to fetch the image form the video server and display. the code is: for (int i = 0; i < dataCount; i++) { doneEvents[i] = new ManualResetEvent(false); ImageReader imgr = new ImageReader(doneEvents[i]); objImageReader[i] = imgr; WaitCallback callback = delegate(object state) { imgr.DownloadFile((structCameraServer)state); }; ThreadPool.QueueUserWorkItem(callback, objServer[i]); } WaitHandle.WaitAll(doneEvents); but how to call the thread again after completion of the work (ie how to make the thread to start again). Thanks in advance,

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          renuga5298 wrote:

          but how to call the thread again after completion of the work (ie how to make the thread to start again).

          Use Thread class other than ThreadPool. Don't end the thread when operation completes. Write your code in a loop and when each cycle completes, sleep for some time.

          Navaneeth How to use google | Ask smart questions

          R 1 Reply Last reply
          0
          • N N a v a n e e t h

            renuga5298 wrote:

            but how to call the thread again after completion of the work (ie how to make the thread to start again).

            Use Thread class other than ThreadPool. Don't end the thread when operation completes. Write your code in a loop and when each cycle completes, sleep for some time.

            Navaneeth How to use google | Ask smart questions

            R Offline
            R Offline
            renuga5298
            wrote on last edited by
            #5

            Can you please guide me in using the thread class for this scenario as i am new to threading

            M 1 Reply Last reply
            0
            • R renuga5298

              Can you please guide me in using the thread class for this scenario as i am new to threading

              M Offline
              M Offline
              MickCurley
              wrote on last edited by
              #6

              If your firing a thread off ever second, I would suggest the BackgroundWorker its a lot easier to manage. You could check if its busy on each Tick and fire it off again if not.

              A craft is an enemy if not well learned.

              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