473,320 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

can't access: System.Web.HttpContext.Current.Cache

A. I need to access: System.Web.HttpContext.Current.Cache

but get this error:

"Object reference not set to an instance of the object"

B. System.Web.HttpContext.Current.Cache is accessible outside of this
class.

I have listed the code below and the offending line of code is delimited by

//The next line breaks: "Object reference not set to an instance of
the object"

Thank you,

John Bickmore

+++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++

using System;
using System.Threading;
using myclasses;

namespace mrFooter
{
public class mrFooter
{
public Thread myThread;

//Parameter(s) go here
string ySessionUser = "";
string yCookieUserEmail = "";

public void Update(string xSessionUser)
{
// init values
ySessionUser = xSessionUser;

CookieUtil myCookie = new CookieUtil();
yCookieUserEmail = myCookie.GetUserEmail();

myThread=new Thread(new ThreadStart(UpdateCache));
myThread.Start();
}

private void UpdateCache()
{
string sUser = "";
bool Continue = true;

try
{
while ( Continue )
{
if ( ySessionUser == null || ySessionUser == String.Empty)
{
Continue = false;
}
else
{

if ( yCookieUserEmail == ySessionUser )
{

//the next line breaks: "Object reference not set to an instance of the
object"
sUser = (string)System.Web.HttpContext.Current.Cache[ySessionUser];
//the previous line breaks: "Object reference not set to an instance of the
object"

Thread.Sleep(System.TimeSpan.FromMilliseconds(1100 00));
Continue = true;
}
else
{
Continue = false;
}
}
}//end while
}// end try
catch(Exception err)
{
Continue = false;
clsErrorsIO myError = new clsErrorsIO();
myError.errMessage = "Error while reading cache";
myError.errNumber=0;
myError.errSourceObject = "clsUpdateFooter";
myError.errSourceEvent = "Update";
myError.errSourceMsg = err.Message.ToString();
myError.ErrorAdd();
}
finally
{
}
}
}//end of class: mrFooter
}//end of Namespace: clsUpdateFooter

Nov 19 '05 #1
3 2713
The context is associated with a specific thread - if you throw
processing onto a second thread, the second thread won't have an
associated context.

See:
http://www.odetocode.com/Articles/112.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 29 Sep 2005 12:58:23 -0600, "xzzy" <mr********@comcast.net>
wrote:
A. I need to access: System.Web.HttpContext.Current.Cache

but get this error:

"Object reference not set to an instance of the object"


Nov 19 '05 #2
Thank you, http://www.odetocode.com/Articles/112.aspx is a good article,
thank you for your reply.

BTW "The 5 Stages Of Mocking" is great! My wife is Canadian, knows
everything about medicine and nothing about software, laughed too. She
wants to know if you sell t-shirts.
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:6c********************************@4ax.com...
The context is associated with a specific thread - if you throw
processing onto a second thread, the second thread won't have an
associated context.

See:
http://www.odetocode.com/Articles/112.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 29 Sep 2005 12:58:23 -0600, "xzzy" <mr********@comcast.net>
wrote:
A. I need to access: System.Web.HttpContext.Current.Cache

but get this error:

"Object reference not set to an instance of the object"

Nov 19 '05 #3
Thanks :) - I don't have any t-shirts at the moment :)

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 29 Sep 2005 19:29:46 -0600, "xzzy" <mr********@comcast.net>
wrote:
Thank you, http://www.odetocode.com/Articles/112.aspx is a good article,
thank you for your reply.

BTW "The 5 Stages Of Mocking" is great! My wife is Canadian, knows
everything about medicine and nothing about software, laughed too. She
wants to know if you sell t-shirts.
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:6c********************************@4ax.com.. .
The context is associated with a specific thread - if you throw
processing onto a second thread, the second thread won't have an
associated context.

See:
http://www.odetocode.com/Articles/112.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 29 Sep 2005 12:58:23 -0600, "xzzy" <mr********@comcast.net>
wrote:
>A. I need to access: System.Web.HttpContext.Current.Cache
>
> but get this error:
>
> "Object reference not set to an instance of the object"
>


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Al Cohen | last post by:
We've got a few methods that take a long time to complete. We're in the process of starting to launch these as separate threads, and having the web form refresh every few seconds to report the...
2
by: Terry Mulvany | last post by:
namespace CIBWeb { public class BasePage : System.Web.UI.Page { public BasePage() { } protected override void OnInit(EventArgs e) {
2
by: Steve W | last post by:
I have an ASP.NET app that calls into some VB.NET components. It passes in the current application's cache (HttpContext.Current.Cache). These VB.NET components also get called by a non-ASP.NET...
17
by: Joe | last post by:
Hello All; I can't access System.Web.HttpServerUtility from within a Class. I want to have access to MapPath. What I get are three options. They are: AspNetHostingPermission...
0
by: bharathreddy | last post by:
Here I will given an example on how to access the session, application and querystring variables in an .cs class file. Using System.Web.HttpContext class. 1) For accesing session variables :...
4
by: msch-prv | last post by:
Hello. I am trying to use caching to populate a datalist. The select method of the associated objectdatasource calls up GetRecipePageByRecipeCatID() to request the proper data (I am using custom...
0
by: =?Utf-8?B?TWFydGlu?= | last post by:
Hi I have a component (vb.net class project) which is used by both a web app and windows app. But it uses Web.HttpContext.Current.Cache , works fine in the web app but refuses to work in the...
6
by: =?Utf-8?B?emlubw==?= | last post by:
in asp.net 2, I load a dataset from the Cache object into a local object to use to perform processing. I had been using httpcontext.current.cache and what I noticed is sometime I'm not able to get...
3
by: Madhur | last post by:
Hello I am delivering an asp.net 2.0 application to my customer. I need to know, If I need to check for the condition of HttpContext.Current to be null in my business logic. I have extensively...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.