Hi,
You can use something like a DispatcherTimer and set its interval to 60000 milliseconds, or, if not available, 1000 milliseconds and then count 60 occurrences of the method.
Then you can do this way:
1. Use the event TextChanged of the RichTextBox control and set a bool flag (called, for istance, Saved) to false to indicate that it is not saved and then start the timer if not already started.
2. In the timer handler, if set to 60000 millis, save the richtextbox and
disable the timer. This way the document does not get saved if no modifies are made in the next minutes.
Here is the code:
FileStream file = new FileStream(filepath, FileMode.Open);
Timer saveTimer = new Timer(60000);
private void startSaveTimer()
{
saveTimer.Elapsed += saveTimer_Elapsed;
saveTimer.Start();
}
private bool saved=true;
private void saveTimer_Elapsed(object sender, ElapsedEventArgs e)
{
string filepath = @"C:\mydoc.txt";
if (!saved)
{
saved=true;
timer.enabled=false;
}
}
private void richText_TextChanged(object sender, TextChangedEventArgs e)
{
saved=false
if(!timer.enabled)
timer.enabled=true;
}
I hope this helps...
PS: I advise you to get the current RichTextBox content and pass it in another thread in order not to block the UI while you are saving... This can save you some troubles :)
LG