Store App State or Settings

Ronald Rex 1,666 Reputation points
2021-09-13T15:03:24.323+00:00

Hi Friends,

I was wondering how is information stored in case while a end user is in the middle of a process and the application or server crashes. If there exists some example code regarding how the information is stored and retrieved? Thanks !!!

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,278 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,071 Reputation points
    2021-09-20T07:56:51.27+00:00

    Hi @Ronald Rex ,

    What's your operating system? If you have win7 operating system,the Windows 7 operating system comes with application recovery and restart (ARR), which allows you to save the data you are currently working on while your application is unresponsive or even crashing, and recover the application and previous data.We'll do this with the Windows API Code Pack.First, let's create a simple WPF program. Registration of ARR is required when the application loads, and ARR is also required to log off when the application is closed.

      <Window x:Class="AppRestartRecovery.MainWindow"  
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
                Title="MainWindow" Height="350" Width="525">  
            <Grid>  
                <Button x:Name="crashBtn" Content="Application Crash"   
                        Margin="169,104,172,168" Click="crashBtn_Click"/>  
                <Button x:Name="closeBtn" Content="Close Application"   
                        Margin="169,189,172,83" Click="closeBtn_Click"/>  
            </Grid>  
        </Window>                                                                                                                                                                                                                                                 Register for ARpublic MainWindow()  
        {  
            InitializeComponent();  
            RegisterForRestartRecovery();  
            ... ...  
        }                                                                                                                                                                                                                                                                            Log off the ARprivate void closeBtn_Click(object sender, RoutedEventArgs e)  
        {  
            UnRegisterRestartRecovery();  
            App.Current.Shutdown();  
        }   
    

    Add Microsoft.WindowsAPICodePack .dll to your project, and add Microsoft.Windows APICodePack.ApplicationServices; The namespace. Next we'll start writing the RegiserForRestart Recovery and UnRegiste


    If the answer is helpful, please click "Accept Answer" and upvote it.

    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.
    Best regards,
    Yijing Sun

    0 comments No comments