Interview questions

How to create and manage threads

<<Previous   Next>>

.NET threading - How to create and manage threads - March 13, 2009 at 15:20 PM by Amit Satpute

Explain how to create and manage threads using Thread class in the System.Threading namespace in .NET. 

using System.Threading;

private void ThreadTask()
{
         int x;
         int val;
         Random r=new Random();

         while(true)
         {
             x=this.progressBar1.Step*r.Next(-1,2);
            val = this.progressBar1.Value + x;
            if (val > this.progressBar1.Maximum)
                  val = this.progressBar1.Maximum;
            else if (val < this.progressBar1.Minimum)
                  val = this.progressBar1.Minimum;
            this.progressBar1.Value = val;
            Thread.Sleep(100);
         }
}

You need to write these lines first:
    Thread t1 = new Thread(new ThreadStart(this.ThreadTask));
    t1.IsBackground = true;
    t1.Start(); 

<<Previous   Next>>
 



Write your comment - Share Knowledge and Experience


 

 
Latest placement tests
Latest links
 
Latest MCQs
» General awareness - Banking » ASP.NET » PL/SQL » Mechanical Engineering
» IAS Prelims GS » Java » Programming Language » Electrical Engineering
» English » C++ » Software Engineering » Electronic Engineering
» Quantitative Aptitude » Oracle » English » Finance
Home | About us | Sitemap | Contact us | We are hiring