Howto: Restart application after CurrentCulture (CurrentUICulture) change

In our applications we use something like this to get/set Frontend Language

      try
      {
          //get language from last user setting...
          Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(Settings.Default.CultureSelected);
      }


CurrentCulture will be set from a settings string...





     Settings.Default.CultureSelected = newLanguage; //"it-IT";
     Settings.Default.Save();

     //Manual restart necessary
     MessageBox.Show(Resources.YouHaveToRestartTheApplicationToAffectTheChangeToTheLanguage, Resources.Warning,
          MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
Bad Example - Messagebox that the user should restart application, why not do it by code?



     Settings.Default.CultureSelected = newLanguage; //"it-IT";
     Settings.Default.Save();
    
     //Restart necessary? yes
     System.Diagnostics.Process.Start(Application.ExecutablePath);
    
     MessageBox.Show(Resources.ApplicationWillBeRestarted, Resources.Warning,
          MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

     // Use this since we are a WinForms app
     System.Windows.Forms.Application.Exit();
Good Example - Automatically restart from code



     Settings.Default.CultureSelected = newLanguage; //"it-IT";
     Settings.Default.Save();
    
     //Restart necessary? yes
     System.Diagnostics.Process.Start(Application.ExecutablePath);
    
     MessageBox.Show(Resources.ApplicationWillBeRestarted, Resources.Warning,
          MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

     
     if (MessageBox.Show(Resources.YouMustRestartTheComputerForTheChangesToTakeEffectNLNLRestartNow, Resources.Warning,
          MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
     {
         //Restart necessary? yes
         System.Diagnostics.Process.Start(Application.ExecutablePath);

         // Use this since we are a WinForms app
         System.Windows.Forms.Application.Exit();
     }    
Good (even better) Example - Ask user if we should restart now...

Thanks to Jury Strumpflohner for his suggestion!


PS
Remember, to start new process and THEN exit... else it want be started



PPS
Remember to set start parameters if you use them



PPPS
If user is in special application area the restart is maybe a bit distracting, cause he's loosing his actual context

  1. i navigated threw a list of articles
  2. selected one
  3. go into modify mode of that article
  4. then change the language of the application --> Restart?

Howto: Affected Rows in Sql-Server and Oracle?

How to get the affected rows (processed rows) from an update Query?

IMMEDIATLY after statement
In Oracle use: SQL%ROWCOUNT
In SQL Server use: @@RowCount


When doing Synchronization of tables this is very useful!!!


Synchronization PseudoCode

       INSERT INTO xxx VALUES SELECT FROM yyy
       EXCEPTION
       WHEN OTHERS
          UPDATE xxx SELECT FROM yyy
Bad Example - catch Exceptions, do something on Exception that is expected (and happens very often)
       CREATE OR REPLACE
       PROCEDURE sample IS
          v_rows_processed integer := 0;
       BEGIN
           UPDATE sample
              SET testno = 1;
              WHERE test   = 'PL/SQL';
           v_rows_processed := SQL%ROWCOUNT;
           IF v_rows_processed := 0
           THEN
               /* Insert Statement */
           END IF;
        END sample;.
Good example - Use processed rowcount in that synch case



thx to my co-worker PK. ps: In Sql-Server @@RowCount works even with SET NOCOUNT OFF. SET NOCOUNT ON says that SQl-Server should print the messages: "rows affected" and "rows returned"

Latest Posts

Popular Posts