Click here to Skip to main content
15,943,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey,

I wish to store a queue<guid> in my application settings. The reason for this is to store a list of the last 10 or so objects loaded and provide a startup screen on my application.

I have MyApp.Properties.Settings.Default.Queue set up but im not sure how to define its type as a queue of guid.

is this possible? or do i need to translate it into something else first, if so what would be reccomended?

Thanks
Posted

1 solution

I didn't read too carefully at the beginnig, now I updated my solution for Queue<Guid>.
You can convert Guid to it's string representation and save queue as collection of strings. You can declare your
C#
MyApp.Properties.Settings.Default.Queue
as
C#
System.Collections.Specialized.StringCollection

Then use form's OnLoad and OnClosed events to read/write your settings:

C#
private Queue<Guid> _queue = new Queue<Guid>();

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    foreach (string item in Properties.Settings.Default.Queue)
    {
        var guid = Guid.Parse(item);
        _queue.Enqueue(guid);
    }
}


protected override void OnClosed(EventArgs e)
{
    Properties.Settings.Default.Queue.Clear();
    
    while(_queue.Count > 0)
    {
        Guid guid = _queue.Dequeue();
        Properties.Settings.Default.Queue.Add(guid.ToString());
    }
    Properties.Settings.Default.Save();
    
    base.OnClosed(e);
}


You can always use your custom type or you can write your custom configuration section.

I hope you'll find this useful :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900