Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > HttpApplication inaccessible in Session_OnEnd:System.NullReferenceException

Reply
Thread Tools

HttpApplication inaccessible in Session_OnEnd:System.NullReferenceException

 
 
Manfred Braun
Guest
Posts: n/a
 
      08-30-2003
Hi All,

In my [global.asa's], I will decrement a counter, like :

protected void Session_End(Object sender, EventArgs e)
{
ActiveSessionCount--; //CRASH !!
}

But, unexpectedly, it give me an "Global_asax]System.NullReferenceException:
Object reference not set to an instance of an object." at line [above] and
line [below].
I handle the increment/decrement of my session-counter with the code below:

protected static int ActiveSessionCount
{

get {
HttpContext.Current.Application.Lock(); //CRASH!!
int i = activeSessionCount; // private static declared.
HttpContext.Current.Application.UnLock();
return i;
}

set {
HttpContext.Current.Application.Lock();
activeSessionCount = value;
HttpContext.Current.Application.UnLock();
}
}

Why can the "HttpContext.Current.Application.Lock();" return a
NullReferenceException??? I am not able to understand this! Any help would
really be very welcomed!!!!

Best regards,
Manfred Braun

(Private)
Mannheim
Germany

(E-Mail Removed)
(Remove the anti-spam-underscore to mail me!)

 
Reply With Quote
 
 
 
 
Steve Donnelly
Guest
Posts: n/a
 
      08-30-2003
HttpContext.Current is a Request context. There is no
request during Session_End(), so HttpContext.Current is
null.

>-----Original Message-----
>Hi All,
>
> In my [global.asa's], I will decrement a counter, like :
>
> protected void Session_End(Object sender, EventArgs e)
> {
> ActiveSessionCount--; //CRASH !!
>}
>
>But, unexpectedly, it give me an "Global_asax]

System.NullReferenceException:
> Object reference not set to an instance of an object."

at line [above] and
>line [below].
>I handle the increment/decrement of my session-counter

with the code below:
>
> protected static int ActiveSessionCount
> {
>
> get {
> HttpContext.Current.Application.Lock(); //CRASH!!
> int i = activeSessionCount; // private static

declared.
> HttpContext.Current.Application.UnLock();
> return i;
> }
>
> set {
> HttpContext.Current.Application.Lock();
> activeSessionCount = value;
> HttpContext.Current.Application.UnLock();
> }
> }
>
>Why can the "HttpContext.Current.Application.Lock();"

return a
>NullReferenceException??? I am not able to understand

this! Any help would
>really be very welcomed!!!!
>
>Best regards,
>Manfred Braun
>
>(Private)
>Mannheim
>Germany
>
>(E-Mail Removed)
>(Remove the anti-spam-underscore to mail me!)
>
>.
>

 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      08-30-2003
"Manfred Braun" <(E-Mail Removed)> wrote in message
news:u%(E-Mail Removed)...
> Hello Steve,
>
> thanks so far, now I am more near to understand what I do
> Do you know, how I can access my application-instance to lock it??
>


For what you're doing, a lock of the Application instance is overkill. Just
use Interlocked.Decrement.
--
John Saunders
Internet Engineer
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
Manfred Braun
Guest
Posts: n/a
 
      08-30-2003
Hi All,

thanks a lot for all the help!!!! I have it working now; Was just
disappointed how to lock the application itself from Session_End(), but
anyway, I have it working!!!

Thanks so far and
best regards,
Manfred

"Sherif ElMetainy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello
>
> you can use the c# lock keyword instead of Application.Lock
> ex.
>
> private static readonly object sync = new object();
>
> protected static int ActiveSessionCount {
> get {
> int i;
> lock(sync) {
> i = activeSessionCount;
> }
> return i;
> } set {
> {
> lock(sync)
> {
> activeSessionCount = value;
> }
> }
> }
>
>
>
> "Manfred Braun" <(E-Mail Removed)> wrote in message
> news:u#(E-Mail Removed)...
> > Hello Steve,
> >
> > thanks so far, now I am more near to understand what I do
> > Do you know, how I can access my application-instance to lock it??
> >
> > Thanks so far and
> > best regards,
> > Manfred
> >
> >
> > "Steve Donnelly" <(E-Mail Removed)> wrote in message
> > news:023701c36f3b$84df82e0$(E-Mail Removed)...
> > > HttpContext.Current is a Request context. There is no
> > > request during Session_End(), so HttpContext.Current is
> > > null.
> > >
> > > >-----Original Message-----
> > > >Hi All,
> > > >
> > > > In my [global.asa's], I will decrement a counter, like :
> > > >
> > > > protected void Session_End(Object sender, EventArgs e)
> > > > {
> > > > ActiveSessionCount--; //CRASH !!
> > > >}
> > > >
> > > >But, unexpectedly, it give me an "Global_asax]
> > > System.NullReferenceException:
> > > > Object reference not set to an instance of an object."
> > > at line [above] and
> > > >line [below].
> > > >I handle the increment/decrement of my session-counter
> > > with the code below:
> > > >
> > > > protected static int ActiveSessionCount
> > > > {
> > > >
> > > > get {
> > > > HttpContext.Current.Application.Lock(); //CRASH!!
> > > > int i = activeSessionCount; // private static
> > > declared.
> > > > HttpContext.Current.Application.UnLock();
> > > > return i;
> > > > }
> > > >
> > > > set {
> > > > HttpContext.Current.Application.Lock();
> > > > activeSessionCount = value;
> > > > HttpContext.Current.Application.UnLock();
> > > > }
> > > > }
> > > >
> > > >Why can the "HttpContext.Current.Application.Lock();"
> > > return a
> > > >NullReferenceException??? I am not able to understand
> > > this! Any help would
> > > >really be very welcomed!!!!
> > > >
> > > >Best regards,
> > > >Manfred Braun
> > > >
> > > >(Private)
> > > >Mannheim
> > > >Germany
> > > >
> > > >(E-Mail Removed)
> > > >(Remove the anti-spam-underscore to mail me!)
> > > >
> > > >.
> > > >

> >

>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Getting a reference to HttpApplication object Michael O'Donovan [MSFT] ASP .Net 0 08-04-2004 03:46 PM
Communication between HttpApplication that run on the same server Sherif ElMetainy ASP .Net 7 11-06-2003 11:23 PM
HttpApplication Init, Application_Start and Application_End don't fire Halcyon Woodward ASP .Net 3 07-16-2003 04:34 PM
httpapplication in ASP.NET modules problem Paul ASP .Net 0 07-11-2003 11:05 PM



Advertisments