473,806 Members | 2,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Object Lifetime

I have a static object that gets referenced at application startup. This
object stores a dataset and various strings to be used whenever required.
This object may be called at anytime to provide the data and strings, but can
be waiting for any length of time period i.e 24hours (this is not a webapp,
but a kiosk winform). 99% of the time, the object is available and when
required provides its information. the 1% of the time, I get a null
reference exeception. Is there any method that will guarantee that the
object will be available for the lifetime of the application?
Any help will be of assistance, thank you
Richard

Nov 16 '05 #1
6 1509
Hi Richard
If you are going to keep this variable for such very long time ( more than
a day ) . Instead of overloading the memory all the time , why don't you
use serializer to serialize it into file and you can desterilize it back
when needed
http://msdn.microsoft.com/library/de...us/dnexxml/htm
l/xml01202003.asp
Mohamed M .Mahfouz
Developer Support Engineer
ITWorx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #2
ok, hadnt thought of that, the reason i have these objects is to store a
dataset in memory (a bit like a cache), that way the database can go offline
(it could be on a different pc) or if the network fails, the kiosk will still
work. Is there a good method to serialize and deserialize all the data
quickly?

"Mohamoss" wrote:
Hi Richard
If you are going to keep this variable for such very long time ( more than
a day ) . Instead of overloading the memory all the time , why don't you
use serializer to serialize it into file and you can desterilize it back
when needed
http://msdn.microsoft.com/library/de...us/dnexxml/htm
l/xml01202003.asp
Mohamed M .Mahfouz
Developer Support Engineer
ITWorx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #3
Hi,

It should be available all the time, at least as long as the appdomain is
active, maybe you get this errors at the start of the application, when the
data is being loaded.

if not give more details of the app. itself

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Richard Steele" <Ri***********@ discussions.mic rosoft.com> wrote in message
news:C3******** *************** ***********@mic rosoft.com...
I have a static object that gets referenced at application startup. This
object stores a dataset and various strings to be used whenever required.
This object may be called at anytime to provide the data and strings, but
can
be waiting for any length of time period i.e 24hours (this is not a
webapp,
but a kiosk winform). 99% of the time, the object is available and when
required provides its information. the 1% of the time, I get a null
reference exeception. Is there any method that will guarantee that the
object will be available for the lifetime of the application?
Any help will be of assistance, thank you
Richard

Nov 16 '05 #4
Ignacio

when the app loads up, all the data is cached into data sets for the life of
the app (or whenever a data refresh is required), each class has its own
dataset and is called upon when required. I have 3 objects (using the same
class) that provide formatted data for 3 functions 1 in particular being a
data driven screen saver. When the app boots,it checks for data issues and
reports accordingly. During the day, the user can update their data using my
own publisher methodology . This effectively disposes all the objects and
rebuilds them using the same method as when the app boots. I am 99.9%
guarenteed that the data is correct, when the app boots and on refresh. The
issue is, when the screen saver has been working for i.e. 12 hours non stop,
the kiosk may want to be used, therefore by a customer pressing a button, the
app comes out of the screen saver mode and goes into search for items mode
(it actually uses an embedded ie browser to show HTML). Last night the app
having been in screen saver mode for 3 hours, was used and a null reference
exception (that was handled) was thrown. is there anyway I can periodically
refresh my objects that are not being used until required, without having to
reresh the whole lot. Thanks very much for your help, hope you understand
what is happening
Richard
"Richard Steele" wrote:
ok, hadnt thought of that, the reason i have these objects is to store a
dataset in memory (a bit like a cache), that way the database can go offline
(it could be on a different pc) or if the network fails, the kiosk will still
work. Is there a good method to serialize and deserialize all the data
quickly?

"Mohamoss" wrote:
Hi Richard
If you are going to keep this variable for such very long time ( more than
a day ) . Instead of overloading the memory all the time , why don't you
use serializer to serialize it into file and you can desterilize it back
when needed
http://msdn.microsoft.com/library/de...us/dnexxml/htm
l/xml01202003.asp
Mohamed M .Mahfouz
Developer Support Engineer
ITWorx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #5
Ignacio

when the app loads up, all the data is cached into data sets for the life of
the app (or whenever a data refresh is required), each class has its own
dataset and is called upon when required. I have 3 objects (using the same
class) that provide formatted data for 3 functions 1 in particular being a
data driven screen saver. When the app boots,it checks for data issues and
reports accordingly. During the day, the user can update their data using my
own publisher methodology . This effectively disposes all the objects and
rebuilds them using the same method as when the app boots. I am 99.9%
guarenteed that the data is correct, when the app boots and on refresh. The
issue is, when the screen saver has been working for i.e. 12 hours non stop,
the kiosk may want to be used, therefore by a customer pressing a button, the
app comes out of the screen saver mode and goes into search for items mode
(it actually uses an embedded ie browser to show HTML). Last night the app
having been in screen saver mode for 3 hours, was used and a null reference
exception (that was handled) was thrown. is there anyway I can periodically
refresh my objects that are not being used until required, without having to
reresh the whole lot. Thanks very much for your help, hope you understand
what is happening
Richard
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

It should be available all the time, at least as long as the appdomain is
active, maybe you get this errors at the start of the application, when the
data is being loaded.

if not give more details of the app. itself

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Richard Steele" <Ri***********@ discussions.mic rosoft.com> wrote in message
news:C3******** *************** ***********@mic rosoft.com...
I have a static object that gets referenced at application startup. This
object stores a dataset and various strings to be used whenever required.
This object may be called at anytime to provide the data and strings, but
can
be waiting for any length of time period i.e 24hours (this is not a
webapp,
but a kiosk winform). 99% of the time, the object is available and when
required provides its information. the 1% of the time, I get a null
reference exeception. Is there any method that will guarantee that the
object will be available for the lifetime of the application?
Any help will be of assistance, thank you
Richard


Nov 16 '05 #6
Hi Richard
in that case of structured data( specially dataset ) best is to use XML
serializer . but since what you are saving is really a dataset it could me
much simpler and more effictive if you just use the WriteXML and ReadXml
Methods of the dataset . you what you would so is simply as follows

MyDataSet.Write Xml("tempFile") ; \\ to save your data
\\ then when you want it back just read it from that temp file
MyNewDataSet..R eadXml("tempFil e");
You might want to use InfroceSchema as the write mode if you want to keep
data constrains and table relations as well.

Mohamed M .Mahfouz
Developer Support Engineer
ITWorx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #7

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

Similar topics

4
1293
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 that perhaps there would not be a need for a destructor because the object would never go out of scope due to the static storage.
5
3760
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 their dtor is called immediately and not at the end of the function. to be able to use return objects (to avoid copying) i often assign them to a const reference. now, casting a const return object from a function to a non-const reference to this...
8
2945
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
3170
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 it makes difference to explicitly put them to null after working with them is done - it somehow makes the GC collect them sooner, like here: void SomeFunc() { MyClass c = new MyClass();
5
2521
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: System.Runtime.InteropServices.Marshal.ReleaseComObject(Obj);
16
2906
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 will stay alive. Is this correct? If this is correct, I've got a problem. Let's say I've got an object Customer that has an PurchaseList (Collection) of Purchase objects. Now, these Purchase objects were pulled from a datasource Datasource. The...
10
8162
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 and excel is closed. But there are some commented lines: //xlSeries.XValues = xlWs.get_Range("B2", "B4"); // makes com objects, but which...
3
2342
by: nagashre | last post by:
class A { public: A():a(0), b(0){} handleMyMsg( char* aa, char*bb); private: processMessage();
6
2701
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; } private:
6
1547
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, Rajesh.S
0
10620
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10369
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10372
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.