-2

I want to load some data from my sql database to the RAM and to be available to be used across all of my forms in C# winform app. I tried REDIS but the problem with it is I coudln't save my object type lists or user defined types in the database. For example,

  • on app launch, I load the data from sql to the RAM

  • during the launch, the data are accessible across all the forms

  • when application is closing, the data saved back to the sql database and updates changed data if any

Is this possible?

What I’m doing already is as follows, on app launch I load all the data from database to an XML file, then I get the data that I want to be used in the forms and I reflect any change to the data in the XML file immediatly. When application is closing, I update the data in sql with what I have in the xml file.

Saeid Amini
  • 1,313
  • 5
  • 16
  • 26
San Nabaty
  • 13
  • 5
  • Once you have loaded the data, where else do you assume it would be stored? (Assuming enough available RAM) I think what you are really asking is a duplicate of https://stackoverflow.com/questions/4247807/passing-variable-between-winforms BUT we'd need much more info / a MCRE (minimal complete reproducible example) – Austin T French Aug 05 '19 at 20:14
  • 1
    @AustinTFrench, yes i know if i load data then yes its in the ram, my point is how do i load the data from one form and then to make it accesible through all of the other forms ? – San Nabaty Aug 05 '19 at 20:21
  • Why you think reading from XML are faster than Redis? – Saeid Amini Aug 05 '19 at 20:28
  • @SaeidAmini, where did i say that reading from XML is faster ? i said REDIS does not allow you to store user type data such as an object type list in the database that easily, so i went with XML, read the whole text before you comment – San Nabaty Aug 05 '19 at 20:31
  • I didn't said you said, actually I said you think. You want to used XML instead of Redis and I think it’s not a good idea. Most of the time Redis used as caching system. – Saeid Amini Aug 05 '19 at 20:48

1 Answers1

1

There's certainly no need to load the data from SQL into memory, then dump that memory into a file, edit the file, and then reverse the process upon application exit. Instead, load your data in your Main() function, saving it to a public static variable that your forms can access. Then, call the methods that run WinForms, editing the static variable (you don't need to worry about thread-safety as long as only your forms code references the variable), and after the forms exit save your data from the variable in the Main() method. I hope that helps!

Douglas Dwyer
  • 562
  • 7
  • 14