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 i can pause/resume a thread in window form application ?

How i can pause/resume a thread in window form application ?

Scheduled Pinned Locked Moved C#
jsonhelptutorialquestioncareer
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.
  • H Offline
    H Offline
    Husnul karim
    wrote on last edited by
    #1

    I am developing an window form application, in which i am playing an audio of wave format, and want to convert that pre recorded speech or audio into text format(using speech api) and display that text in the label. I started a thread for audio to text conversion in the play button, now i want to pause that thread on the pause button(means how to pause a that thread). I used ManualEventReset method. but in the pause button when i am using signal.waitone() methods. this freez the whole form. please help.some parts of my code is given here. //pause button

     ManualResetEvent signal = new ManualResetEvent(false);
    
     ManualResetEvent signal = new ManualResetEvent(false);
    

    private void buttonX15_Click(object sender, EventArgs e)
    {
    method_pause();
    }

    public void method_pause()
    {

           clip.Pause();
           visular1.Stop();
           visular2.Stop();
           visular3.Stop();
           visular4.Stop();
           visular5.Stop();
           this.pause.Hide();
           signal.WaitOne();
           play.Show();
       }
    

    private void play_Click(object sender, EventArgs e)
    {

          playsub();
          labelX1.Text = "Play";
       }
    

    public void playsub()
    {
    starter = delegate { subt(FName); };
    thread=new Thread(starter);

            try
            {
                thread.Start();
                method\_play();
    
            }
           catch(Exception ex){}
    
       }
    

    from where i can set the thread.

    P 1 Reply Last reply
    0
    • H Husnul karim

      I am developing an window form application, in which i am playing an audio of wave format, and want to convert that pre recorded speech or audio into text format(using speech api) and display that text in the label. I started a thread for audio to text conversion in the play button, now i want to pause that thread on the pause button(means how to pause a that thread). I used ManualEventReset method. but in the pause button when i am using signal.waitone() methods. this freez the whole form. please help.some parts of my code is given here. //pause button

       ManualResetEvent signal = new ManualResetEvent(false);
      
       ManualResetEvent signal = new ManualResetEvent(false);
      

      private void buttonX15_Click(object sender, EventArgs e)
      {
      method_pause();
      }

      public void method_pause()
      {

             clip.Pause();
             visular1.Stop();
             visular2.Stop();
             visular3.Stop();
             visular4.Stop();
             visular5.Stop();
             this.pause.Hide();
             signal.WaitOne();
             play.Show();
         }
      

      private void play_Click(object sender, EventArgs e)
      {

            playsub();
            labelX1.Text = "Play";
         }
      

      public void playsub()
      {
      starter = delegate { subt(FName); };
      thread=new Thread(starter);

              try
              {
                  thread.Start();
                  method\_play();
      
              }
             catch(Exception ex){}
      
         }
      

      from where i can set the thread.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You haven't posted all your code and it looks, to me, that you are starting the video through your method_play method, which is happening on the primary thread.

      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