473,385 Members | 1,342 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,385 software developers and data experts.

Object Lifetime.


Hi,
I am still new to dotnet programming, and ASP.NET in general.

Something that has been bugging me for a while is this:

In a Web Form application, using C# in the codebehind. If I have a drop
down combobox filled with a list of stuff, like employee names etc. I
can select a persons name and see the codebehind event fired. No news
flash there then.
However, if I leave the web form open for a few minutes, make a coffee
etc, then come back, and choose a different user name, I get 'blah blah
not set to an instance of an object' exception.

It looks like the garbage collector has cleaned up my Combobox.

I am missing something fundamental about dotnet programming?
I have tried a few things, like making some stuff static etc, nothing
helps.

I am using VS2005 on XP.

Regards

Jan 3 '07 #1
2 1407
Hi,
I am still new to dotnet programming, and ASP.NET in general.

Something that has been bugging me for a while is this:

In a Web Form application, using C# in the codebehind. If I have a drop
down combobox filled with a list of stuff, like employee names etc. I
can select a persons name and see the codebehind event fired. No news
flash there then.
However, if I leave the web form open for a few minutes, make a coffee
etc, then come back, and choose a different user name, I get 'blah blah
not set to an instance of an object' exception.

It looks like the garbage collector has cleaned up my Combobox.

I am missing something fundamental about dotnet programming?
I have tried a few things, like making some stuff static etc, nothing
helps.

I am using VS2005 on XP.

Regards
"static" will have (possibly) surprising effects in web programming: as
the web application is a single application that serves multiple users,
*all* users will then share the same instance of that static variable.
(which you do not want in this case).

That combobox is destroyed as soon as the page finishes rendering, that
is, as soon as the html has been sent to the browser. A new request
(which can be a "postback") is served by a new instance of the page.

How long was that "few minutes"? If it was more than 20, then you have
hit the session timeout (20 minutes is the default, maybe you set it to
a lower number?). If it was not the session timeout (or you didn't use
session variables) then obviously it's something else. In that case you
need to show some of your code.

Hans Kesting
Jan 4 '07 #2
Hi,

Control Freq wrote:
Hi,
I am still new to dotnet programming, and ASP.NET in general.

Something that has been bugging me for a while is this:

In a Web Form application, using C# in the codebehind. If I have a drop
down combobox filled with a list of stuff, like employee names etc. I
can select a persons name and see the codebehind event fired. No news
flash there then.
However, if I leave the web form open for a few minutes, make a coffee
etc, then come back, and choose a different user name, I get 'blah blah
not set to an instance of an object' exception.

It looks like the garbage collector has cleaned up my Combobox.

I am missing something fundamental about dotnet programming?
I have tried a few things, like making some stuff static etc, nothing
helps.

I am using VS2005 on XP.

Regards
We would need to see some code (if possible trimmed to the max in order
to get the most information from the smallest amount of code possible
:-) to say more, but if waiting without doing anything else creates such
a big difference, the first suspect is a session timeout.

If you wait long enough (default: 20 minutes) without "stimulating" a
web application, the Session is recycled. It means that everything you
stored in it is destroyed.

However, since the session ID is stored in the client, the next time you
connect (for example by firing an event), a new Session object is
created. If your code gets stuff from the Session without checking first
if it is null, you may very well get that exception.

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jan 4 '07 #3

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

Similar topics

4
by: johny smith | last post by:
Suppose there is a policy that all objects are statically declared. For example: static Car car(); Then, is there a reason to have a destructor defined for the class Car. It would seem...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
8
by: pt | last post by:
Hallo, i wonder how it is going to be of this code below regarding of the return of temporary object. Prototypes: =========== bool Activation(TCHAR *c); std::basic_string<TCHAR> GetFile();
14
by: MuZZy | last post by:
Hi, Lately i've been (and still am) fixing some memory leaks problems in the project i just took over when i got this new job. Among the other issues i've noticed that for localy created objects...
5
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
16
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener...
10
by: Hendri Adriaens | last post by:
Hi, I'm trying to automate the creation of an excel file via COM. I copied my code below. I read many articles about how to release the COM objects that I create. The code below runs just fine...
3
by: nagashre | last post by:
class A { public: A():a(0), b(0){} handleMyMsg( char* aa, char*bb); private: processMessage();
6
by: better_cs_now | last post by:
Hello all, class Foo {/* Details don't matter */}; class Bar { public: Bar(): m_Foo(/* Construct a Foo however it wants to be constructed */); const Foo &GetFoo() const { return m_Foo; }...
6
by: Rajesh | last post by:
I read Global Object's constructor will be called before main() function; In which situation it can be really helpful? Is it good practice use Global object and its constructor ? Thanks,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.