Link to home
Create AccountLog in
Avatar of aspnetdev
aspnetdev

asked on

Application State manager

Hi,
I have to create a generic state manager dll.Attached file has the code snippet of my dll.Can any one help me out with this.I am bit confused still.But it seems this dll should save everything that a programmer does and write it on the app.config file and when the application loads it should read the values from this file.For E.g:If the user change the size of the window and change the location then this should be written down in the xml file.I know its bit confusing but if you guys look at the attached file and able to make out do let me know.Also,i would like to know how do i refrence this dll in my app and how do i invoke it to write it on the config file.This is applicable for win forms only.Also,if the application is idle then the dll's idle method should be invoked...do have a look at it and let me know asap...its urgent.
Thanks
Thanks,
smgr.txt
Avatar of ripahoratiu
ripahoratiu
Flag of Romania image

In a twisted way it does the work... Not sure in deep if always correct...

First:
Somewhere, when your app starts you have to set once the path (a string or by getting it from Environment/Application variables). You have to do that just once.
i.e.:
SMgr.SManager.Instance.setPath(@"C:\Projects\MyApp\MyApp\bin\Debug\WindowsApplication3.exe");
or
string exePath = System.IO.Path.Combine(
        Environment.CurrentDirectory, "WindowsApplication3.exe");
SMgr.SManager.Instance.setPath(exePath );

Now let's say you want to save/retrieve your Form1.Height:
in Form1_Load handler

           string returnedSetting = SMgr.SManager.Instance.Get("Form1.Height"); //I named "Form1.Height"  the key that youll find in "WindowsApplication3.exe.config" xml where the height of form1 will be saved
            if (returnedSetting.Length != 0) // unfortunately this can happen, and empty string cannot be parsed
                this.Height = Int32.Parse(SMgr.SManager.Instance.Get("Form1.Height"));


In Form1_ResizeEnd handler you have to set the new value:
SMgr.SManager.Instance.Set("Form1.Height", Height.ToString());

finally, when your application is idle or when you leave the application or at some (any) point in time you decide to save all settings (kept in the List for the lifetime of app, in memory). Than just invoke:
SMgr.SManager.Instance.Idle(); //that will save in the config file WindowsApplication3.exe.config your settings.
Avatar of aspnetdev
aspnetdev

ASKER

Hi Ripahoratiu,
Thanks for quick reply.I got few quick questions
1)Is there any method or event for application Idle?
2)It seems i will have to replace the
private static List<string> DirtyList = new List<string>(100);
with a dictionary.Can you tell me how do i do that?
Prompt reply would really be appreciated.
Thanks,
ASKER CERTIFIED SOLUTION
Avatar of ripahoratiu
ripahoratiu
Flag of Romania image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thanks a bunch...can you tell me little more on locking.It seems i have to lock an object as you told..an you tell me how do i add lock logic in my manager code.
Thanks,