private readonly object balanceLock = new object(); //object used as a lock for Threading. /* * SaveImageCache method is used to Save the List into Json format and then save it in a json file. */ public void SaveImageCache() { JSONImageList jsonList = new JSONImageList(); jsonList.JSONImages = jsonimageslist; string json = JsonConvert.SerializeObject(jsonList); //Serialize the object string filename = @"..\...\..\ImageCache.json"; //Filename File.WriteAllText(filename, json); //Write the json Text to the File and save it. }
/* * ReadImageCache is used to Read the ImageCache.json file. * Fills the global variable jsonimageslist with the contents from the json file. */ public void ReadImageCache() { try{ string json = File.ReadAllText(@"..\...\..\ImageCache.json"); //try read file. JSONImageList jsonimageList = JsonConvert.DeserializeObject <JSONImageList>(json); //DeserializeObject jsonimageslist = (List <JSONImage>)jsonimageList.JSONImages; //Fill jsonimageslist } catch (Exception e) { Console.WriteLine(" Exception Caught. Cache does not exist."); //File Could not be read, does not exist. } }