private void removeMenuItem_Click(object sender, EventArgs e) { int idx = modelsBox.SelectedIndex; // Validating item if (idx == -1) { return; } string modelName = modelsBox.Items[idx].ToString(); // Fetching process LivestreamerProcess listener = _listeners[modelName]; // Initiating termination listener.Terminate(); // Removing listener from lists modelsBox.Items.RemoveAt(idx); LivestreamerProcess output; _listeners.TryRemove(modelName, out output); Logger.Log(modelName, "Remove"); }
private void removeAllUncheckedToolStripMenuItem_Click_1(object sender, EventArgs e) { // Gather IDs ArrayList modelIds = new ArrayList(); for (int i = 0; i < modelsBox.Items.Count; i++) { if (modelsBox.GetItemCheckState(i) == CheckState.Unchecked) { modelIds.Add(i); } } // Reverse so we start at the end, or as we remove elements the indexes will be incorrect modelIds.Reverse(); // Batch remove foreach (int id in modelIds) { string modelName = modelsBox.Items[id].ToString(); // Fetching process LivestreamerProcess listener = _listeners[modelName]; // Initiating termination listener.Terminate(); // Removing listener from lists modelsBox.Items.RemoveAt(id); LivestreamerProcess output; _listeners.TryRemove(modelName, out output); Logger.Log(modelName, "Remove all unchecked"); } }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { // Asking user to confirm action if (_listeners.Count > 0 && MessageBox.Show(this, "Are you sure you want to quit, all active streams being listened to will be terminated.", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) { e.Cancel = true; return; } // Terminating manager thread if (_listenerThread.IsAlive) { try { _listenerThread.Abort(); } catch (ThreadAbortException) { } } // Terminating operational threads/process foreach (KeyValuePair <string, LivestreamerProcess> valuePair in _listeners) { // Fetching listener string modelName = valuePair.Key; LivestreamerProcess listener = valuePair.Value; // Initiating termination listener.Terminate(); // Removing listener from list LivestreamerProcess output; _listeners.TryRemove(modelName, out output); } }