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. Threading in C# !

Threading in C# !

Scheduled Pinned Locked Moved C#
csharphelptutorial
3 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.
  • L Offline
    L Offline
    lucdt
    wrote on last edited by
    #1

    I have developed an application ! In my main class, I call 8 Threading to work something. My main class must to wait all 8 Threading end in order to continute do something. I don't known how to suspend my main class to wait all 8 Threading end. How to known all 8 Threading end. Pls, help me ! Thank alots !

    A 1 Reply Last reply
    0
    • L lucdt

      I have developed an application ! In my main class, I call 8 Threading to work something. My main class must to wait all 8 Threading end in order to continute do something. I don't known how to suspend my main class to wait all 8 Threading end. How to known all 8 Threading end. Pls, help me ! Thank alots !

      A Offline
      A Offline
      Andy Brummer
      wrote on last edited by
      #2

      If you have 8 threads and one task per thread which completes when the thread is complete, then you can do something like this: [edit] I just re-read the docs and WaitAll won't work for threads. The best you can do is something like what I have below, I'd use delegates and use beginInvoke and endInvoke because you can use WaitHandle.WaitAll plus your threads are running from the thread pool so it will be faster. [/edit]

      bool WaitForThreads(Thread[] threads)
      {
      foreach(Thread t in threads)
      {
      if (!t.Join(1))
      {
      return false;
      }
      }
      return true;
      }

      Then in your function

      while (!WaitForThreads(threads))
      Application.DoEvents();


      I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon

      -- modified at 23:51 Sunday 11th September, 2005

      L 1 Reply Last reply
      0
      • A Andy Brummer

        If you have 8 threads and one task per thread which completes when the thread is complete, then you can do something like this: [edit] I just re-read the docs and WaitAll won't work for threads. The best you can do is something like what I have below, I'd use delegates and use beginInvoke and endInvoke because you can use WaitHandle.WaitAll plus your threads are running from the thread pool so it will be faster. [/edit]

        bool WaitForThreads(Thread[] threads)
        {
        foreach(Thread t in threads)
        {
        if (!t.Join(1))
        {
        return false;
        }
        }
        return true;
        }

        Then in your function

        while (!WaitForThreads(threads))
        Application.DoEvents();


        I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon

        -- modified at 23:51 Sunday 11th September, 2005

        L Offline
        L Offline
        lucdt
        wrote on last edited by
        #3

        Thank you very much ! I have tried the methord you suggest. It done well. Thank again !

        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