I need a thread that loads the content of a database table in the cache
(System.Web.Cac hing.Cache)
i wrote therefore the code below:
public class Global : System.Web.Http Application
{
.....
......
......
public static Thread t;
{
get { return post; }
}
public Global()
{
InitializeCompo nent();
}
public static String GetConnectionSt ring
{
get { return ConfigurationSe ttings.AppSetti ngs["DBConnStr"]; }
}
protected void Application_Sta rt(Object sender, EventArgs e)
{
DataSet
ds=SqlHelper.Ex ecuteDataset(Gl obal.GetConnect ionString,Comma ndType.Text,"se lect
* from table");
HttpContext.Cur rent.Cache.Inse rt("data",ds.Ta ble[0],null,Cache.NoA bsoluteExpirati on,System.TimeS pan.FromHours(2 ));
t = new Thread(new ThreadStart(Thr eadProc));
t.Start();
Thread.Sleep(36 00);
}
.....
......
.......
public void ThreadProc()
{
try
{
DataSet
ds=SqlHelper.Ex ecuteDataset(Gl obal.GetConnect ionString,Comma ndType.Text,"se lect
* from Table");
HttpContext.Cur rent.Cache.Inse rt("data",ds.Ta bles[0],null,Cache.NoA bsoluteExpirati on,System.TimeS pan.FromHours(2 ));
}
catch(Exception ex)
{
string str = ex.Message; // get the exeption as a string
}
....
......
.....
But!!!
This cause the exception: "object reference not set to an instance of
anobject"
Can someone tell me what i'm doing wrong?
Many thanks in advance
JB
Comment