Results 1 to 2 of 2

Thread: Suspending and Resuming a Thread?

  1. #1

    Thread Starter
    Lively Member neodatatype's Avatar
    Join Date
    Aug 2002
    Location
    Italy
    Posts
    103

    Question Suspending and Resuming a Thread?

    Hi all!


    I would like to suspend a thread and then resume it with the same procedure.

    I would expected that this code (you can just cut-and-paste into a new console project) will do the thing, but when i do the Resume() nothing happen!

    Why it does not restart the Execute() procedure???

    PHP Code:
    using System
    using System.Threading

    namespace 
    thread 


    public class 
    Class1 


    public static 
    void Main() 

    ThreadedClass t = new ThreadedClass(); 

    t.Start(); 
    Thread.Sleep(10); 
    t.Suspend(); 
    Console.WriteLine("NOW RESUME!");
    t.Resume(); 
    Thread.Sleep(10); 
    t.Abort(); 





    public class 
    ThreadedClass 

    private 
    Thread oThread

    public 
    ThreadedClass() 

    oThread = new Thread(new ThreadStart(this.Execute)); 


    public 
    void Start() 

    oThread.Start(); 


    public 
    void Abort() 

    oThread.Abort(); 
    oThread.Join(); 



    public 
    void Suspend() 

    oThread.Suspend(); 


    public 
    void Resume() 

    oThread.Resume(); 


    private 
    void Execute() 

    do 

    Console.WriteLine(DateTime.Now.ToString() + " - Executing"); 

    while (
    true); 





    Last edited by neodatatype; Mar 2nd, 2003 at 10:30 AM.
    > NeoDataType.net <

    Try my Free .Net Reporting Tool!

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    probably because you are puting the thread to sleep for 20 ms imemdiatly after resuming, then aborting it immediatly after that.

    what sense does it make to have

    t.Resume();
    Thread.Sleep(10);
    t.Abort();

    ?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width