public void OpenForm() { // open a new form on a non-background, STA thread using (ProcessKeepalive.Open()) // throws exception if we are shutting down { // this object will be signalled when the new thread has // finished incrementing object signalIncremented = new object(); Thread formThread = ThreadHelper.NewThread( ThreadStartWithParams.Create(new ThreadStartWithParamsDelegate(ThreadMain), signalIncremented), "FormThread", true, true, false); lock (signalIncremented) { formThread.Start(); // Don't continue until refcount has been incremented Monitor.Wait(signalIncremented); } } }
private void Main() { try { // delay the check for updates Thread.Sleep(1000); // only run one service-update at a time process wide lock (_serviceUpdateLock) { // establish settings detection context ServiceUpdateSettingsDetectionContext settingsDetectionContext = new ServiceUpdateSettingsDetectionContext(_blogId); // fire-up a blog settings detector to query for changes BlogSettingsDetector settingsDetector = new BlogSettingsDetector(settingsDetectionContext); settingsDetector.SilentMode = true; using (RegistryKey key = Registry.CurrentUser.OpenSubKey(ApplicationEnvironment.SettingsRootKeyName + @"\Weblogs\" + _blogId + @"\HomepageOptions")) { if (key != null) { settingsDetector.IncludeFavIcon = false; settingsDetector.IncludeCategories = settingsDetectionContext.BlogSupportsCategories; settingsDetector.UseManifestCache = true; settingsDetector.IncludeHomePageSettings = false; settingsDetector.IncludeCategoryScheme = false; settingsDetector.IncludeInsecureOperations = false; } } settingsDetector.IncludeImageEndpoints = false; settingsDetector.DetectSettings(SilentProgressHost.Instance); // write the settings using (ProcessKeepalive.Open()) { using (BlogSettings settings = BlogSettings.ForBlogId(_blogId)) settings.ApplyUpdates(settingsDetectionContext); } // if changes were made then fire an event to notify the UI if (settingsDetectionContext.HasUpdates) { _settingsChangedHandler(_blogId, false); } } } catch (ManualKeepaliveOperationException) { } catch (Exception ex) { Trace.Fail("Unexpected exception during ServiceUpdateChecker.Main: " + ex.ToString()); } }
private void ThreadMain(object[] parameters) { IDisposable splashScreen = null; if (parameters.Length > 0) { splashScreen = parameters[parameters.Length - 1] as IDisposable; } ProcessKeepalive pk = null; try { try { pk = ProcessKeepalive.Open(); } finally { object signalIncremented = parameters[0]; lock (signalIncremented) Monitor.Pulse(parameters[0]); } // housekeeping initialization Application.OleRequired(); UnexpectedErrorDelegate.RegisterWindowsHandler(); // Create and run the form SatelliteApplicationForm applicationForm = (SatelliteApplicationForm)Activator.CreateInstance(_formType, _parameters); Application.Run(applicationForm); } catch (Exception ex) { UnexpectedErrorMessage.Show(ex); } finally { if (pk != null) { pk.Dispose(); } if (splashScreen != null) { Debug.Assert(splashScreen is FormSplashScreen); splashScreen.Dispose(); } } }
public static void LaunchBloggingForm(string[] args, IDisposable splashScreen, bool isFirstInstance) { try { using (ProcessKeepalive.Open()) { UpdateManager.CheckforUpdates(); // If the COM registration is not set up correctly, we won't be able to launch. RunningObjectTable.EnsureComRegistration(); // make sure blogging is configured before we proceed if (EnsureBloggingConfigured(splashScreen)) { WriterCommandLineOptions options = WriterCommandLineOptions.Create(args); // check for a prefs request if (options.IsShowPreferences) { if (splashScreen != null) { splashScreen.Dispose(); } ExecuteShowPreferences(options.PreferencesPage); } // check for an open-post request else if (options.IsOpenPost) { if (splashScreen != null) { splashScreen.Dispose(); } ExecuteOpenPost(); } // check for opening an existing post via the shell file association else if (options.IsPostEditorFile) { ExecutePostEditorFile(options.PostEditorFileName, splashScreen); } // check for recovered posts else if (isFirstInstance && RecoverPosts(splashScreen)) { return; } // launch with an new empty post else { ExecuteNewPost(splashScreen, null); } } } } catch { if (splashScreen != null) { splashScreen.Dispose(); } throw; } }