public IProgressVisualizer CreateVisualizer(bool allowCancel) { DefaultProgressVisualizer visualizer = null; _asyncOp.Send( () => { visualizer = new DefaultProgressVisualizer(allowCancel); _flowLayoutPanel.Controls.Add(visualizer); }); _asyncOp.Post( () => { if (!Visible) { ShowDialog( _serviceProvider .GetRequiredService <IUIShell>() .GetMainWindowParent()); } }); return(visualizer); }
private void EnableAutoSync() { _uiAsyncOperation.Send( () => { _timer = new Timer { Interval = Config.Instance.AutoSyncInterval * 1000 }; _timer.Tick += TimerTick; _timer.Start(); }); _startSyncSubscription = _synchronizer.StartSync.Subscribe(args => _timer.Stop()); _endSyncSubscription = _synchronizer.EndSync.Subscribe(args => _timer.Start()); _isEnabled = true; }
private void BeforeForumEntryChanged(ForumEntryChangedEventArgs args) { _asyncOperation.Send( () => { bool isWholeForum; if (Forums.Instance.ActiveForum == null || !args.Entries.IsContainsForum(Forums.Instance.ActiveForum.ID, out isWholeForum)) { return; } if (isWholeForum) { _tgMsgs.Nodes = null; } StopMarkTimer(); }); }
public static TResult Send <TResult>( [NotNull] this AsyncOperation asyncOp, [NotNull] Func <TResult> valueGetter) { if (asyncOp == null) { throw new ArgumentNullException("asyncOp"); } if (valueGetter == null) { throw new ArgumentNullException("valueGetter"); } var result = default(TResult); asyncOp.Send(() => { result = valueGetter(); }); return(result); }
public NotifyIconService([NotNull] IServiceProvider serviceProvider) { if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } _serviceManager = new ServiceManager(serviceProvider); _defaultCommandService = new DefaultCommandService("Janus.Application.ShowMainForm"); _serviceManager.Publish(_defaultCommandService); _uiAsyncOperation = _serviceManager .GetRequiredService <IUIShell>() .CreateUIAsyncOperation(); _uiAsyncOperation.Send( () => { _notifyIcon = new NotifyIcon(); _notifyIcon.DoubleClick += NotifyIconDefaultAction; _notifyIcon.BalloonTipClicked += NotifyIconDefaultAction; Ticker.Instance.DoubleClick += NotifyIconDefaultAction; }); }
private IStatisticsContainer PerformSyncSession( Action <ISyncContext> syncProc, bool activateUI) { var stats = new StatisticsContainer(); if (!InitStartSync()) { return(stats); } var svcManager = new ServiceManager(_provider); SyncForm syncForm = null; var result = SyncResult.Failed; Exception failException = null; try { var context = new SyncContext( svcManager, stats, // ReSharper disable AccessToModifiedClosure () => syncForm != null && syncForm.IsCancelled); // ReSharper restore AccessToModifiedClosure if (_lastSyncFormInstance != null) { _uiAsyncOp.Send(_lastSyncFormInstance.Dispose); } if (Config.Instance.ShowSyncWindow) { _uiAsyncOp.Send( () => { syncForm = new SyncForm(context) { WindowState = activateUI ? FormWindowState.Normal : FormWindowState.Minimized }; syncForm.Show(); }); syncForm.Closed += (sender, args) => _lastSyncFormInstance = null; _lastSyncFormInstance = syncForm; svcManager.Publish <ISyncProgressVisualizer>(syncForm); svcManager.Publish <ITaskIndicatorProvider>(syncForm); svcManager.Publish <ISyncErrorInformer>(syncForm); } syncProc(context); if (!stats.IsEmpty()) { _provider.LogInfo(stats.GetFormattedValues(_provider)); } result = SyncResult.Finished; } catch (UserCancelledException ex) { _provider.LogWarning(SyncResources.SyncWarning.FormatStr(ex.Message)); result = SyncResult.Aborted; } catch (Exception ex) { _provider.LogError(SyncResources.SyncError.FormatStr(ex.Message)); result = SyncResult.Failed; failException = ex; } finally { _isActive = false; OnEndSync(new EndSyncEventArgs(stats, result, failException)); if (syncForm != null) { _uiAsyncOp.Send(syncForm.TryClose); } } return(stats); }
public void Dispose() { ContextMenuName = null; _uiAsyncOperation.Send(() => _notifyIcon.Dispose()); _uiAsyncOperation.OperationCompleted(); }