What is Threading?
-Parallel execution of code pieces on CPU, commonly compiled codes started in a single thread but it is possible to create multi-threads within a program.

Why Threading?
-Because threading is really useful, and it is used in nearly all kind of serious softwares, threads enables us to do independent jobs simultaneously, and it is sometimes hard to handle, if it is done with experienced hands, it enhances the software greatly. I want to give a simple example, consider you want your program to check for available updates and install them without interrupting the user’s work. This is only done with threads, while user working with your software, another thread connects to Internet and checks available updates without blocking the current execution of the software.

A simple threading example with C# :

Thread test_thread;

public void Thread_Task()
{
for(int i=0;i<100:++i)
TextBox1.Text=Convert.ToString(i);
}
private void button1_Click(object sender, EventArgs e)
{
test_thread=new Thread(new ThreadStart(this.Thread_Task));
test_thread.IsBackground = true;
test_thread.Start();
}

In the above simple code piece, we created a thread object and a thread task function, then we assigned task function to thread object in a button_click function, then we started the thread, as you notice, if user clicks the button a new thread starts and show the value of i in the TextBox1 without blocking the program, user may continue working and at the same time values of i are showed in the TextBox1. This was a sample example to demonstrate threads created and used, besides there is a vast usage and restrictions for threads, for example there will be a problem what if two threads wants to access the same resource and wants to edit, there are lots of synchronization problems and techniques.

Share this ! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • blinkbits
  • BlinkList
  • blogmarks
  • BlogMemes
  • blogtercimlap
  • Blue Dot
  • Book.mark.hu
  • Bumpzee
  • co.mments
  • connotea
  • De.lirio.us
  • DotNetKicks
  • Fark
  • feedmelinks
  • Fleck
  • Furl
  • Gwar
  • Haohao
  • Hemidemi
  • IndiaGram
  • IndianPad
  • Internetmedia
  • kick.ie
  • LinkaGoGo
  • Linkter
  • Ma.gnolia
  • MyShare
  • Netscape
  • NewsVine
  • PlugIM
  • PopCurrent
  • ppnow
  • RawSugar
  • Rec6
  • Reddit
  • Scoopeo
  • scuttle
  • Shadows
  • Simpy
  • Slashdot
  • Smarking
  • SphereIt
  • Spurl
  • StumbleUpon
  • Taggly
  • TailRank
  • Technorati
  • Webride
  • Wykop
  • YahooMyWeb

Some other posts that you may like :

USB Fan that does not worth a penny !
Google Tip
Linux and BSD - Why so segregated?
Simple Text Editor with Java Swing
Cool Your Hands With This Device
Mechanical Head
Wireless Pen Mouse
5 GHz Overclocking Attempt
Starcraft II
Starcraft Proxy Problem