Skip to content

Save a Queue object to the Registry

leighton

Asked Nov 13, 2008, 9:08 PM ESTSolved
Share
LinkedInX

Hello,
Is it possible to save a System.Collection.Queue object to the Registy?

Im trying the below code to save a Queue containing most Recent file name to the registry in the REG Binary format. Cant seem to get it work.

TypeScript
public static void saveRecentFile(string strFilePath)
{
try
{
string strBaseKey = "MyApp\\RecentEvents";
//Open Key;
RegistryKey key = Registry.CurrentUser.OpenSubKey(strBaseKey, true);
//If Key does not exist then create it
if (key == null)
{
Registry.CurrentUser.CreateSubKey(strBaseKey);
}
Queue arrMRU = (Queue)key.GetValue("MRU");
{
if (arrMRU == null)
{
arrMRU = new Queue(intMaxMRUFileCount);
arrMRU.Enqueue(strFilePath);
}
else
{
if (arrMRU.Count == intMaxMRUFileCount)
{
arrMRU.Dequeue();
}
arrMRU.Enqueue(strFilePath);
}
//Save queue in registry in binary format

key.SetValue("MRU",arrMRU,RegistryValueKind.Binary);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}

}

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    ✓ Accepted answer+1
    Before responding I have a question, do you want to register the values in the Queue or the Queue it self?
    +1
  • +1

    I got it.

    I wanted to register the queue itself.

    Im doing it using Serialization to convert it to a byte array.

    Thanks

    +1
  • 1 short reply
    • Bechir Bejaoui
      +1
      Perfect!!
      +1