public MainPresenter(ITimeManager timeManager, IProcessInfoService processInfoService, IProcessDetailService processDetailService, IMainForm view, ILoggerFactory loggerFactory) { _timeManager = timeManager; _processInfoService = processInfoService; _processDetailService = processDetailService; _view = view; _loggerFactory = loggerFactory; _ctoken = new CancellationTokenSource(); _timeManager.Tick += _timeManager_Tick; _view.MainFormLoad += _view_MainFormLoad; _view.MainFormFormClosed += _view_MainFormFormClosed; _view.AddProcessInfo += _view_AddProcessInfo; }
private void _view_ProcessInfoControlClick(object sender, EventArgs e) { try { var isOpen = sender as bool?; var processDetails = _view.GetProcessDetails; if (isOpen == true) { _processInfoService = new ProcessInfoService(processDetails.ProcessName); TaskScheduler scheduler = TaskScheduler.FromCurrentSynchronizationContext(); _processInfoService.LoadProcessesInfo(_ctoken) .ContinueWith(ant => { _loggerFactory.UserOpenInfoLogged(processDetails); _timeManager.Tick += _timeManager_Tick; }, CancellationToken.None, TaskContinuationOptions.None, scheduler); } else { _loggerFactory.UserCloseInfoLogged(processDetails); _timeManager.Tick -= _timeManager_Tick; if (_processInfoService != null) { _processInfoService.Dispose(); } } } catch (Exception ex) { _loggerFactory.ErrorLogged(ex); } }