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.
 | 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: |
|