private static FwXWindow RefreshCacheWindowAndAll(LexTextApp app, string fullProjectFileName) { var manager = app.FwManager; var appArgs = new FwAppArgs(fullProjectFileName); var newAppWindow = (FwXWindow)manager.ReopenProject(manager.Cache.ProjectId.Name, appArgs).ActiveMainWindow; if (IsVernacularSpellingEnabled(newAppWindow.Mediator)) { WfiWordformServices.ConformSpellingDictToWordforms(newAppWindow.Cache); } //clear out any sort cache files (or whatever else might mess us up) and then refresh newAppWindow.ClearInvalidatedStoredData(); newAppWindow.RefreshDisplay(); return(newAppWindow); }
public static int Main(string[] rgArgs) { // Create a semaphore to keep more than one instance of the application // from running at the same time. If the semaphore is signalled, then // this instance can run. Win32.SecurityAttributes sa = new Win32.SecurityAttributes(); IntPtr semaphore = Win32.CreateSemaphore(ref sa, 1, 1, Process.GetCurrentProcess().MainModule.ModuleName); switch (Win32.WaitForSingleObject(semaphore, 0)) { case Win32.WAIT_OBJECT_0: // Using the 'using' gizmo will call Dispose on app, // which in turn will call Dispose for all FdoCache objects, // which will release all of the COM objects it connects to. using (LexTextApp application = new LexTextApp(rgArgs)) { SIL.Utils.ErrorReporter.EmailAddress = "*****@*****.**"; application.Run(); } int previousCount; Win32.ReleaseSemaphore(semaphore, 1, out previousCount); break; case Win32.WAIT_TIMEOUT: // If the semaphore wait times out then another instance is running. // Try to get a handle to its window and activate it. Then terminate // this process. try { IntPtr hWndMain = ExistingProcess.MainWindowHandle; if (hWndMain != (IntPtr)0) { Win32.SetForegroundWindow(hWndMain); } } catch { // The other instance does not have a window handle. It is either in // the process of starting up or shutting down. } break; } return(0); }
public static int Main(string[] rgArgs) { // Create a semaphore to keep more than one instance of the application // from running at the same time. If the semaphore is signalled, then // this instance can run. Win32.SecurityAttributes sa = new Win32.SecurityAttributes(); IntPtr semaphore = Win32.CreateSemaphore(ref sa, 1, 1, Process.GetCurrentProcess().MainModule.ModuleName); switch (Win32.WaitForSingleObject(semaphore, 0)) { case Win32.WAIT_OBJECT_0: // Using the 'using' gizmo will call Dispose on app, // which in turn will call Dispose for all FdoCache objects, // which will release all of the COM objects it connects to. using (LexTextApp application = new LexTextApp(rgArgs)) { SIL.Utils.ErrorReporter.EmailAddress = "*****@*****.**"; application.Run(); } int previousCount; Win32.ReleaseSemaphore(semaphore, 1, out previousCount); break; case Win32.WAIT_TIMEOUT: // If the semaphore wait times out then another instance is running. // Try to get a handle to its window and activate it. Then terminate // this process. try { IntPtr hWndMain = ExistingProcess.MainWindowHandle; if (hWndMain != (IntPtr)0) Win32.SetForegroundWindow(hWndMain); } catch { // The other instance does not have a window handle. It is either in // the process of starting up or shutting down. } break; } return 0; }