question

LuckyBC-1075 avatar image
0 Votes"
LuckyBC-1075 asked RoyLi-MSFT edited

How to make a c# uwp app autosave a file or a list of files

Hi,

I am working a small project of editing text files in C# UWP, but I want my app can autosave the unsaved files over a period, for example 10s. How do I do that?

dotnet-csharpwindows-uwp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RoyLi-MSFT avatar image
1 Vote"
RoyLi-MSFT answered RoyLi-MSFT edited

Hello,

Welcome to Microsoft Q&A!

I want my app can autosave the unsaved files over a period, for example 10s. How do I do that?

You could use aDispatcherTimer Class to achieve this.

Using DispatcherTimer Class;

  DispatcherTimer dispatcherTimer;
    
         private void MainPage_Loaded(object sender, RoutedEventArgs e)
         {
             DispatcherTimerSetup();
         }
    
         public void DispatcherTimerSetup()
         {
             dispatcherTimer = new DispatcherTimer();
             dispatcherTimer.Tick += DispatcherTimer_Tick;
             dispatcherTimer.Interval = new TimeSpan(0, 0, 10);
             dispatcherTimer.Start();
         }
    
         private void DispatcherTimer_Tick(object sender, object e)
         {
             //save the text
             var text = MyTextBox.Text;
         }

Thank you.


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.