private void StartStopHandler() { var _uiDispatcher = Dispatcher.CurrentDispatcher; if (!IsRun) { IsRun = true; Output.Clear(); _threadManager.Init(ValueToFind, ThreadsCount, Delay); _threadManager.Start((x) => { lock ( Output ) { if (!_threadManager.IsAborted && IsRun) { Action act = () => { if (IsRun) { Output.Add(x); } }; _uiDispatcher.Invoke(act); } else { if (IsRun) { IsRun = false; Action msgBox = () => { MessageBox.Show("Число найдено!", "Сообщение"); _threadManager.Stop(); }; _uiDispatcher.Invoke(msgBox); } } } }); } else { IsRun = false; _threadManager.Stop(); } }