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 Do I correct Thread Program?

How Do I correct Thread Program?

Scheduled Pinned Locked Moved C#
question
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.
  • P Offline
    P Offline
    pubududilena
    wrote on last edited by
    #1

    Hi All, I need to run 3 methods parallaly.Then I have used Threading for that. Here is the code. public void threadtest() { Thread SpecialThread = new Thread(new ThreadStart(this.GetSpecial)); Thread BulkThread = new Thread(new ThreadStart(this.GetBulk)); Thread NormalThread = new Thread(new ThreadStart(this.GetNormal)); SpecialThread.Start(); BulkThread.Start(); NormalThread.Start(); SpecialThread.Join(); BulkThread.Join(); NormalThread.Join(); while((NormalThread.ThreadState==System.Threading.ThreadState.Running) || (BulkThread.ThreadState==System.Threading.ThreadState.Running) || (SpecialThread.ThreadState==System.Threading.ThreadState.Running) ) { } } But most of time one or two threads are going to aborted or something happen and I loose their results.Sometimes this worked properly and I can get all results from 3 methods. Can any one correct this code?

    H 1 Reply Last reply
    0
    • P pubududilena

      Hi All, I need to run 3 methods parallaly.Then I have used Threading for that. Here is the code. public void threadtest() { Thread SpecialThread = new Thread(new ThreadStart(this.GetSpecial)); Thread BulkThread = new Thread(new ThreadStart(this.GetBulk)); Thread NormalThread = new Thread(new ThreadStart(this.GetNormal)); SpecialThread.Start(); BulkThread.Start(); NormalThread.Start(); SpecialThread.Join(); BulkThread.Join(); NormalThread.Join(); while((NormalThread.ThreadState==System.Threading.ThreadState.Running) || (BulkThread.ThreadState==System.Threading.ThreadState.Running) || (SpecialThread.ThreadState==System.Threading.ThreadState.Running) ) { } } But most of time one or two threads are going to aborted or something happen and I loose their results.Sometimes this worked properly and I can get all results from 3 methods. Can any one correct this code?

      H Offline
      H Offline
      Harvey Saayman
      wrote on last edited by
      #2

      dude! please get in the habbit of using pre and code tags for code in your posts, its hard to read if you dont

      Harvey Saayman - South Africa Junior Developer .Net, C#, SQL think BIG and kick ASS

      If (Programming != Your Passion)
      {
      you.suck = true;
      }
      else
      {
      you.suck = false;
      }

      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