Object Lifetime

G

Guest

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
 
G

Guest

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?
 
I

Ignacio Machin \( .NET/ C# MVP \)

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,
 
G

Guest

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
 
G

Guest

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
 
M

Mohamoss

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.WriteXml("tempFile"); \\ to save your data
\\ then when you want it back just read it from that temp file
MyNewDataSet..ReadXml("tempFile");
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top