View Single Post
Old Apr 17th, 2008, 5:32 PM   #3
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
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

c# Syntax (Toggle Plain Text)
  1. Class asdjkfj
  2. {
  3. string autoSavePrefix = "";
  4. ...
  5. private void btnSave1_Click(object sender, EventArgs e)
  6. {
  7. StreamWriter write1 = new StreamWriter
  8. ( "C:\\" + autoSavePrefix + txtSaveName.Text );
  9.  
  10. write1.WriteLine(txtfield1.Text);
  11. write1.WriteLine(txtfield2.Text);
  12. write1.WriteLine(txtfield3.Text);
  13.  
  14. write1.Close();
  15. }
  16. ....
  17. private void timer_Tick(object sender, EventArgs e)
  18. {
  19. DateTime autosave = DateTime.Today;
  20. if (txtSaveName.Visible == true)
  21. {
  22. autoSavePrefix = "Auto Saved";
  23. btnSave1_Click(null, null);
  24. autoSavePrefix = "";
  25. }
  26. }
OpenLoop is offline   Reply With Quote