Can any one help to solve the Thread error here
I am getting the following error when i execute the program.
Server Error in '/threaad' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 48: for(int i=1;i<20;i++)
Line 49: {
Line 50: t[i].Start();
Line 51: }
Line 52:
Source File: c:\inetpub\wwwroot\threaad\webform1.aspx.cs Line: 50
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
threaad.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\threaad\webform1.aspx.cs:50
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
<CODE Here>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.Data.SqlClient;
namespace threaad
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btn1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Thread t1 = new Thread( new ThreadStart( sayHello));
Thread t2 = new Thread( new ThreadStart( sayHello));
Thread t3 = new Thread( new ThreadStart( sayHello));
Thread t4 = new Thread( new ThreadStart( sayHello));
Thread t5 = new Thread( new ThreadStart( sayHello));
Thread t6 = new Thread( new ThreadStart( sayHello));
Thread t7 = new Thread( new ThreadStart( sayHello));
Thread t8 = new Thread( new ThreadStart( sayHello));
Thread t9 = new Thread( new ThreadStart( sayHello));
Thread t10 = new Thread( new ThreadStart( sayHello));
Thread t11 = new Thread( new ThreadStart( sayHello));
Thread t12 = new Thread( new ThreadStart( sayHello));
Thread t13 = new Thread( new ThreadStart( sayHello));
Thread t14 = new Thread( new ThreadStart( sayHello));
Thread t15 = new Thread( new ThreadStart( sayHello));
Thread t16 = new Thread( new ThreadStart( sayHello));
Thread t17 = new Thread( new ThreadStart( sayHello));
Thread t18 = new Thread( new ThreadStart( sayHello));
Thread t19 = new Thread( new ThreadStart( sayHello));
Thread t20 = new Thread( new ThreadStart( sayHello));
Thread [] t = new Thread[20];
for(int i=1;i<20;i++)
{
t[i].Start();
}
DateTime start = DateTime.Now;
Response.Write("PROGRAM STARTED.AT.."+start.TimeOfDay );
Response.Write("<br>");
DateTime end = DateTime.Now;
Response.Write("\nPROGRAM ENDED...at "+end.TimeOfDay);
Response.Write("<br><br>");
Response.Write("\nTime Taken : " + (end.Millisecond - start.Millisecond));
btn1.Attributes.Add("onclick","javascript:clicked( )");
}
static void sayHello()
{
SqlConnection con = new SqlConnection("server=comp17;database=POS;user id=sa;password=cmie");
//string qry = "SELECT * FROM PRODUCTS WHERE MFG_NAME LIKE ' "+ condition + "%' ";
string qry = "SELECT TOP 10000 * FROM PRODUCTS ";
SqlCommand myCmd = new SqlCommand(qry,con);
DataSet ds = new DataSet();
myCmd.Connection.Open();
myCmd.ExecuteNonQuery();
myCmd.Connection.Close();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
Vivek Shah
__________________
Vivek Shah
|