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. started thread to wait till the other thread finishes

started thread to wait till the other thread finishes

Scheduled Pinned Locked Moved C#
questioncareer
2 Posts 2 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.
  • K Offline
    K Offline
    ksanju1000
    wrote on last edited by
    #1

    hi i have started one thread. it has read four lines. After that i want to wait that thread so that second thread so that execute. HOw can i wait a particular thread. i do not to use Thread.sleep(500); it stops all the thread. I want to wait that thread for some time or tilll other threads completed its job. thanks

    S 1 Reply Last reply
    0
    • K ksanju1000

      hi i have started one thread. it has read four lines. After that i want to wait that thread so that second thread so that execute. HOw can i wait a particular thread. i do not to use Thread.sleep(500); it stops all the thread. I want to wait that thread for some time or tilll other threads completed its job. thanks

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

      Thread.Sleep will only cause the thread on which you called it to sleep, it won't affect other threads. If you have specific places in code where you want to wait/notify, you can use the AutoResetEvent[^] class. Something like

      class Test
      {
      AutoResetEvent evt = new AutoResetEvent(false);
      void Thread1()
      {
      // do operation 1
      evt.WaitOne();
      // do operation 2
      }
      void Thread2()
      {
      // do some other operation
      evt.Set(); // signal other thread to resume
      // do something else
      }

      Regards Senthil _____________________________ My Blog | My Articles | WinMacro

      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