![]() |
Autosaving Streams in C#
Hi All
I have decided to implement a little autosave function into my application that is used for datacapturing, but for some reason I am having some trouble. Example... Let's say I have three fields that text data can be stored in: txtfield1, txtfield2, and txtfield3. I also have a seperate btn(bntSave) that when clicked, writes the entered data to the specifics I want it to. Also add a text box(txtSaveName) used to specify the filename if desired. Now, the event for the button would look something like this: :
private void btnSave1_Click(object sender, EventArgs e):
private void timer_Tick(object sender, EventArgs e)My reason for asking is that I have about 90 or so fields that I am working with, so I would like to keep my code clean.:) I have tried something similar and it only saved when I minimized the application's window or when I exited, where I wanted it to save more often, but not sure how to activate the autosave function with the timer?:?: Should I rather let it autosave for, when example, a field is being left, by implementing it's leave event? All help will be much appreciated. Thanks >BstrucT |
Re: Autosaving Streams in C#
First off, you can add all those textboxes to an array or other collection, such that you can iterate through them. This is very handy if you're performing identical operations on multiple textboxes, such as validation, serialization, etc. Stick it in the form's handler for the Load event, or something:
:
:
|
Re: Autosaving Streams in C#
You can set the timer interval to say 120 seconds, and it will save every two minutes by calling timer_tick.
Try this :
|
Re: Autosaving Streams in C#
Wow, thanks for the great advice guys.
@lectricpharaoh: Thanks for showing me how to implement it by putting all those frisky fields into an array then just work with the array as a whole. This should make my life a lot easier regarding code repitition!:) @Openloop: Will definitely take a closer look at your timer function and see how I can implement it. Thanks for the great advice guys, gonna get cracking on the code right away!:P >BstrucT |
| All times are GMT -5. The time now is 4:09 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC