469,928 Members | 1,827 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,928 developers. It's quick & easy.

Thread in a webservice.


I need a thread that loads the content of a database table in the cache
(System.Web.Caching.Cache)

i wrote therefore the code below:
public class Global : System.Web.HttpApplication

{

.....

......

......
public static Thread t;


{

get { return post; }

}
public Global()

{

InitializeComponent();

}

public static String GetConnectionString

{

get { return ConfigurationSettings.AppSettings["DBConnStr"]; }

}

protected void Application_Start(Object sender, EventArgs e)

{

DataSet
ds=SqlHelper.ExecuteDataset(Global.GetConnectionSt ring,CommandType.Text,"select
* from table");
HttpContext.Current.Cache.Insert("data",ds.Table[0],null,Cache.NoAbsoluteExpiration,System.TimeSpan.F romHours(2));
t = new Thread(new ThreadStart(ThreadProc));

t.Start();

Thread.Sleep(3600);


}

.....

......

.......
public void ThreadProc()

{

try

{

DataSet
ds=SqlHelper.ExecuteDataset(Global.GetConnectionSt ring,CommandType.Text,"select
* from Table");
HttpContext.Current.Cache.Insert("data",ds.Tables[0],null,Cache.NoAbsoluteExpiration,System.TimeSpan.F romHours(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
Nov 17 '05 #1
3 4846
Hi,

What is the line that gives you that error?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"jensen bredal" <je***********@yahoo.dk> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

I need a thread that loads the content of a database table in the cache
(System.Web.Caching.Cache)

i wrote therefore the code below:
public class Global : System.Web.HttpApplication

{

....

.....

.....
public static Thread t;


{

get { return post; }

}
public Global()

{

InitializeComponent();

}

public static String GetConnectionString

{

get { return ConfigurationSettings.AppSettings["DBConnStr"]; }

}

protected void Application_Start(Object sender, EventArgs e)

{

DataSet
ds=SqlHelper.ExecuteDataset(Global.GetConnectionSt ring,CommandType.Text,"select
* from table");
HttpContext.Current.Cache.Insert("data",ds.Table[0],null,Cache.NoAbsoluteExpiration,System.TimeSpan.F romHours(2));
t = new Thread(new ThreadStart(ThreadProc));

t.Start();

Thread.Sleep(3600);


}

....

.....

......
public void ThreadProc()

{

try

{

DataSet
ds=SqlHelper.ExecuteDataset(Global.GetConnectionSt ring,CommandType.Text,"select
* from Table");
HttpContext.Current.Cache.Insert("data",ds.Tables[0],null,Cache.NoAbsoluteExpiration,System.TimeSpan.F romHours(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

Nov 17 '05 #2

in "ThreadProc" the line:

HttpContext.Current.Cache.Insert("data",ds.Table[0],null,Cache.NoAbsoluteExpiration,System.TimeSpan.F romHours(2));


"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:ON**************@TK2MSFTNGP15.phx.gbl...
Hi,

What is the line that gives you that error?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"jensen bredal" <je***********@yahoo.dk> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

I need a thread that loads the content of a database table in the cache
(System.Web.Caching.Cache)

i wrote therefore the code below:
public class Global : System.Web.HttpApplication

{

....

.....

.....
public static Thread t;


{

get { return post; }

}
public Global()

{

InitializeComponent();

}

public static String GetConnectionString

{

get { return ConfigurationSettings.AppSettings["DBConnStr"]; }

}

protected void Application_Start(Object sender, EventArgs e)

{

DataSet
ds=SqlHelper.ExecuteDataset(Global.GetConnectionSt ring,CommandType.Text,"select
* from table");
HttpContext.Current.Cache.Insert("data",ds.Table[0],null,Cache.NoAbsoluteExpiration,System.TimeSpan.F romHours(2));
t = new Thread(new ThreadStart(ThreadProc));

t.Start();

Thread.Sleep(3600);


}

....

.....

......
public void ThreadProc()

{

try

{

DataSet
ds=SqlHelper.ExecuteDataset(Global.GetConnectionSt ring,CommandType.Text,"select
* from Table");
HttpContext.Current.Cache.Insert("data",ds.Tables[0],null,Cache.NoAbsoluteExpiration,System.TimeSpan.F romHours(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


Nov 17 '05 #3
Your cache object is null most probably. Try passing in a reference to the
cache object to your thread.

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc
"jensen bredal" <je***********@yahoo.dk> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...

in "ThreadProc" the line:

HttpContext.Current.Cache.Insert("data",ds.Table[0],null,Cache.NoAbsoluteExpiration,System.TimeSpan.F romHours(2));


"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote in message news:ON**************@TK2MSFTNGP15.phx.gbl...
Hi,

What is the line that gives you that error?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"jensen bredal" <je***********@yahoo.dk> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

I need a thread that loads the content of a database table in the cache
(System.Web.Caching.Cache)

i wrote therefore the code below:
public class Global : System.Web.HttpApplication

{

....

.....

.....
public static Thread t;


{

get { return post; }

}
public Global()

{

InitializeComponent();

}

public static String GetConnectionString

{

get { return ConfigurationSettings.AppSettings["DBConnStr"]; }

}

protected void Application_Start(Object sender, EventArgs e)

{

DataSet
ds=SqlHelper.ExecuteDataset(Global.GetConnectionSt ring,CommandType.Text,"select
* from table");
HttpContext.Current.Cache.Insert("data",ds.Table[0],null,Cache.NoAbsoluteExpiration,System.TimeSpan.F romHours(2));
t = new Thread(new ThreadStart(ThreadProc));

t.Start();

Thread.Sleep(3600);


}

....

.....

......
public void ThreadProc()

{

try

{

DataSet
ds=SqlHelper.ExecuteDataset(Global.GetConnectionSt ring,CommandType.Text,"select
* from Table");
HttpContext.Current.Cache.Insert("data",ds.Tables[0],null,Cache.NoAbsoluteExpiration,System.TimeSpan.F romHours(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



Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Tomaz Koritnik | last post: by
4 posts views Thread by Elementary Penguin | last post: by
2 posts views Thread by dhow | last post: by
8 posts views Thread by Jason Chu | last post: by
3 posts views Thread by Ted Ngo | last post: by
reply views Thread by roni schuetz | last post: by
1 post views Thread by ryan1234 | last post: by
3 posts views Thread by =?Utf-8?B?Sm9obiBT?= | last post: by
4 posts views Thread by Simon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.