2

I have a winform application that uses some referenced web services to get data. The data returned is an array of objects that I loop through and add to a dataSet.

When I call the service, it can often take 2 or 3 minutes to get all the data.

If the user exits the program and comes back later, I don't want them to have to re-download all the data again.

When I run the app in debug mode, there's no persistence of the downloaded information; which worries me.

I'm still in "development mode", so I haven't really put together an installer yet to test if the information stays with the application.

I'm curious about a couple of things:

  1. Does the data stored in the dataset remain after the user exits?
  2. If not, what would you recommend on how to accomplish this?
  3. I've considered XML for storage; is that the best option when you have 9-10 MB of data?
    Edit: Final Outcome: OK - here's the final outcome (thank you everyone for your quick response)

When the application exits, I call a function to save the data. Here's a snippet:

   using System.IO;
   using System.Runtime.Serialization;
   using System.Runtime.Serialization.Formatters.Binary;            
   FileStream fs;
   IFormatter formatter = new BinaryFormatter();
    //activities
    if (actList.Length > 0)
    {
        fs = new FileStream("activities.bin", FileMode.Create, FileAccess.Write, FileShare.None);
        formatter.Serialize(fs, actList);
        fs.Close();
    }
    //users
    if (userList.Length > 0)
    {
        fs = new FileStream("users.bin", FileMode.Create, FileAccess.Write, FileShare.None);
        formatter.Serialize(fs, userList);
        fs.Close();
    }

The userList and actList parameters are List objects that came from the web services call.

another thing I implemented (slightly off topic) is to create an application setting to save when the user last did a download from the web service. It's saved as

Properties.Settings.Default.last_downloaded

If the user clicks the download button, they are prompted with the date they last performed the download and are given a chance to say "no".

Thanks again for your help!

JayTee
  • 2,776
  • 2
  • 24
  • 27
  • If you are web-service based, consider ClickOnce instead of a regular installer - much simpler to deploy. – Marc Gravell Feb 05 '09 at 14:55
  • I don't think I can use ClickOnce and persist the data at the same time, can I? I thought that with ClickOnce, I can't "leave behind" any data: http://msdn.microsoft.com/en-us/library/ms973805.aspx – JayTee Feb 05 '09 at 15:40
  • Nevermind...answered my own question :) – JayTee Feb 05 '09 at 16:20

2 Answers2

2

A .NET object has no persistance unless you write it yourself - for example by serializing to a file in the user's profile (or isolated storage for ClickOnce).

Note: personally, I wouldn't use DataSet at all in this scenario; if you are downloading the data as a list of objects, then just keep them like that - List<T> etc.

Re xml: 9-10Mb is big but not immense. It really depends on the nature of the data and other requirements; unless you are already using web-compression (GZIP etc), you might find that the data transfers quicker with a more compact format, such as csv, or a binary format such as protocol buffers.

Community
  • 1
  • 1
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • I'm actually using the dataset as the source of data for a couple of datagridviews and listboxes; is there a way to use the list to populate those things? – JayTee Feb 05 '09 at 14:55
  • List can be used just fine as the DataSource for DataGridView and ListBox etc. – Marc Gravell Feb 05 '09 at 14:59
  • Strictly speaking, anything that is `IList` or `IListSource` will work - `List` benefits from a `public T this[int]` indexer which provides stronger metadata than just `IList`. But main point: there is no issue using `List` – Marc Gravell Feb 05 '09 at 15:01
1

You need to manually persist any data that you want to save. What you can do is take your Dataset, and, when your application is closing, serialize the dataset to a file. Then when the app opens, if the file exists, deserialize the dataset from that file instead of calling the webservice.

GWLlosa
  • 23,995
  • 17
  • 79
  • 116