3
Answers

Save a Queue object to the Registry

leighton

leighton

16y
3.2k
1

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.

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);

}

}

Answers (3)