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. thread resume with out using sleep method

thread resume with out using sleep method

Scheduled Pinned Locked Moved C#
csharplinqhelpcareer
3 Posts 3 Posters 1 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.
  • S Offline
    S Offline
    somasekhara777
    wrote on last edited by
    #1

    hi i suspend a thread now i have to resume that thread but with out using sleep method the code is below using System; using System.Threading; using System.Collections.Generic; using System.Linq; using System.Text; namespace threadsuspend { public class myclass { public void method() { for (int i = 1; i <= 10; i++) { Console.WriteLine(Thread.CurrentThread.Name + "=" + i); if (i == 5) { Console.WriteLine(Thread.CurrentThread.Name +" is going to suspend"); Thread.CurrentThread.Suspend(); } Thread.CurrentThread.Resume(); } } } class Program { static void Main(string[] args) { myclass mc = new myclass(); Thread thr1 = new Thread(new ThreadStart(mc.method)); Thread thr2 = new Thread(new ThreadStart(mc.method)); thr1.Start(); thr2.Start(); thr1.Name = "ntr"; thr2.Name = "anr"; Console.ReadLine(); } } } please help me out thanks to you

    j somasekhar

    M L 2 Replies Last reply
    0
    • S somasekhara777

      hi i suspend a thread now i have to resume that thread but with out using sleep method the code is below using System; using System.Threading; using System.Collections.Generic; using System.Linq; using System.Text; namespace threadsuspend { public class myclass { public void method() { for (int i = 1; i <= 10; i++) { Console.WriteLine(Thread.CurrentThread.Name + "=" + i); if (i == 5) { Console.WriteLine(Thread.CurrentThread.Name +" is going to suspend"); Thread.CurrentThread.Suspend(); } Thread.CurrentThread.Resume(); } } } class Program { static void Main(string[] args) { myclass mc = new myclass(); Thread thr1 = new Thread(new ThreadStart(mc.method)); Thread thr2 = new Thread(new ThreadStart(mc.method)); thr1.Start(); thr2.Start(); thr1.Name = "ntr"; thr2.Name = "anr"; Console.ReadLine(); } } } please help me out thanks to you

      j somasekhar

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Another thread would have to resume a suspended thread. Regardless, you shouldn't be using those methods anyway - they aren't only deprecated, they're marked obsolete. What are you trying to do? Surely you can use proper synchronization objects?

      Mark Salsbery :java:

      1 Reply Last reply
      0
      • S somasekhara777

        hi i suspend a thread now i have to resume that thread but with out using sleep method the code is below using System; using System.Threading; using System.Collections.Generic; using System.Linq; using System.Text; namespace threadsuspend { public class myclass { public void method() { for (int i = 1; i <= 10; i++) { Console.WriteLine(Thread.CurrentThread.Name + "=" + i); if (i == 5) { Console.WriteLine(Thread.CurrentThread.Name +" is going to suspend"); Thread.CurrentThread.Suspend(); } Thread.CurrentThread.Resume(); } } } class Program { static void Main(string[] args) { myclass mc = new myclass(); Thread thr1 = new Thread(new ThreadStart(mc.method)); Thread thr2 = new Thread(new ThreadStart(mc.method)); thr1.Start(); thr2.Start(); thr1.Name = "ntr"; thr2.Name = "anr"; Console.ReadLine(); } } } please help me out thanks to you

        j somasekhar

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, please keep your code nicely formatted, using PRE[^] tags does that for you. Probably the only time it makes sense for a thread to suspend itself, is when another thread is going to resume it. A suspended thread cannot resume itself, it is dead and buried for all intents and purposes, i.e.

        Thread.CurrentThread.Resume();

        is nonsense. :)

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        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