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

Lucky B.C 51 Reputation points
2022-04-27T19:36:11.623+00:00

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?

Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,450 questions
0 comments No comments
{count} votes

Accepted answer
  1. Roy Li - MSFT 32,646 Reputation points Microsoft Vendor
    2022-04-28T03:04:05.31+00:00

    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.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful