How to make an object to survive application restart?

  • Thread starter Thread starter Vadim Rapp
  • Start date Start date
V

Vadim Rapp

My application in vb.net is using a collection of structures, implementing
basically a queue of jobs. What is the easiest way to make this collection
surviving application restart? Is there some embedded universal way to save
each member of the collection, for example to an XML file, and then restore
them upon restart? I understand that I can code the export of every
particular object, but thought maybe there's some universal way like
object.ExportToXML <path> / object = loader.load <path>

thanks
 
Vadim,

You will want to take a look at either Serialization (using a
BinaryFormatter or a SoapFormatter), XML serialization (using the
XmlSerializer) or the DataContractSerializer. My recommendation is for the
DataContractSerializer. It will allow you to persist object graphs to
streams.
 
Vadim said:
My application in vb.net is using a collection of structures, implementing
basically a queue of jobs. What is the easiest way to make this collection
surviving application restart? Is there some embedded universal way to save
each member of the collection, for example to an XML file, and then restore
them upon restart? I understand that I can code the export of every
particular object, but thought maybe there's some universal way like
object.ExportToXML <path> / object = loader.load <path>

thanks
Vadim, try a vb newsgroup this is C#
 
Hi

This is a C# group, not VB.

apart from that you need to serialize the data to the HDD and then
reload if when the appliaction runs again.
If your structs are simple enough then you have to do nothing to
serialize/deserialize it.
 
Vadim said:
My application in vb.net is using a collection of structures, implementing
basically a queue of jobs. What is the easiest way to make this collection
surviving application restart?

Write them to files.

(Actually, is there any particular reason you don't /keep/ them in
files/directories anyway? This would be much more resilient for those
"odd" occasions where your application or the machine it's running on,
suddenly "disappears" for some strange reason).
Is there some embedded universal way to save each member of the collection,
for example to an XML file, and then restore them upon restart?

That sounds like Serialisation which /should/ work, just so long as
every Type that you're working with is marked as Serializable.
If just /one/ Class isn't marked that way, then your Save mechanism will
break.
I understand that I can code the export of every particular object,

.... and that's a Good Thing, because you have complete control over what
gets saved and how you choose to read it back again ...
but thought maybe there's some universal way like
object.ExportToXML <path> / object = loader.load <path>

Even if there were such a method, every object is different and you'd
probably wind up overriding the default implementation anyway.

HTH,
Phill W.
 
Back
Top