.Net Framework, Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML

Ado.netAsp.Net 2.0SQLC-SharpXMLFrameworkIISXMLWebServiceArchitecture
UMLProject ManagementSDLCMethodologiesDesign PatterenOOPWCF.Net RemotingWWF
MVPMVCSilver LightN-HibernateAjaxJ-QuerySEO-MarketingSite MapPhp

Multi Threading in Asp.net

What is MultiThreading ? || also see Threading || Asyc Call in Asp.net

Multithreading is a technique that can be used to perform time consuming tasks (like a I/O operation, sending bulk mails) in a separate additional thread other than the main application thread.





Must Consider before you start with multithreading
Each time a thread is created, a certain amount of memory is consumed to hold this thread related information. Always runtime overhead associated with creating and destroying threads. When your application creates and destroys threads frequently, this overhead affects the overall application performance.

The .NET framework provides you with a class library that allows you to overcome this problem by using multithreading and asynchronous programming techniques
Disadvantages of Multi Threading
Each time a thread is created, a certain amount of memory is consumed to hold this thread context information. Hence, the number of threads that can be created is limited by the amount of available memory.
So, There is a runtime overhead associated with creating and destroying threads. When your application creates and destroys threads frequently, this overhead affects the overall application performance. Having too many threads running at the same time decreases the performance of your entire system.


Let's look at the implementation steps
using System.Threading;
Multi Threading Example
public partial class MultithreadingAspNet : System.Web.UI.Page
1: {
2:
3: protected void Page_Load(object sender, EventArgs e)
4: {
5:
6: }
7:
8:
9: void MyLongTask(object sender)
10: {
11: StringBuilder _objstr = new StringBuilder();
12:
13: for (Int64 i = 0; i < 100; i++)
14: {
15: _objstr.Append( i.ToString() + " Time " + DateTime.Now.Millisecond.ToString() +"<br>");
16:
17: }
18:
19: lblThreadOutput.Text = _objstr.ToString();
20: }
21:
22: protected void btnThreadStart_Click(object sender, EventArgs e)
23: {
24: if (ThreadPool.QueueUserWorkItem(new WaitCallback(MyLongTask) ) )
25: {
26: lblThreadresult.Text += "Queued successfully at " + DateTime.Now.TimeOfDay.TotalMilliseconds.ToString() + "<br>";
27: }
28: else
29: {
30: lblThreadresult.Text += "Queued failed at " + DateTime.Now.TimeOfDay.TotalMilliseconds.ToString();
31: }
32:
33: }
34: }
35:
Leave your comment.
Name
Email
Comments
Tell Us5247+5 =

Reduce your Dialy IT Cost, Consult with us
Stay healthy in recession

Advertisement
Sponsored by

Privacy Policy ©2009 ETG Consultancy, All Rights Reserved Terms & Conditions
Asp.net, Ado.net, .Net Remoting, .Net Webservice, SQL, XML, XSLT, WCF, WPF, WWF NHibernate, Ajax, Jquery, DHTML