public static void SuspendThreadList(ProcessThreadCollection threads, bool suspend) { int[] threadList = new int[threads.Count]; for (int i = 0; i < threadList.Length; i++) { threadList[i] = threads[i].Id; } IDL.SuspendThreadList(threadList, threadList.Length, suspend ? 1 : 0); }
private void buttonLoad_Click(object sender, EventArgs e) { if (mainForm.ActiveDocument == null) { label_Result.Text = "No active document"; return; } if (mainForm.ActiveDocument.DocumentType != DocumentType.BgData && mainForm.ActiveDocument.DocumentType != DocumentType.ObjectData && mainForm.ActiveDocument.DocumentType != DocumentType.StageData) { label_Result.Text = "Unsupported document type: " + mainForm.ActiveDocument.DocumentType; return; } int result = int.MinValue; try { if (comboBox_Process.SelectedIndex < 0 || (comboBox_DataType.SelectedIndex < 0) || (comboBox_DataType.SelectedIndex == 0 && (comboBox_ObjId.SelectedIndex < 0 || comboBox_ObjType.SelectedIndex < 0)) || (comboBox_DataType.SelectedIndex == 2 && (comboBox_BgId.SelectedIndex < 0))) { return; } string dat = mainForm.ActiveDocument.Scintilla.Text; Process p = procs[comboBox_Process.SelectedIndex]; if (p.HasExited) { RefreshProcessList(); return; } p = Process.GetProcessById(p.Id); // refresh for most up-to-date thread list int[] threads = new int[p.Threads.Count]; for (int i = 0; i < threads.Length; i++) { threads[i] = p.Threads[i].Id; } int suspendResult; var suspend = (int[])threads.Clone(); var resume = (int[])threads.Clone(); try { if ((suspendResult = IDL.SuspendThreadList(suspend, threads.Length, 1)) != 0) { throw new ApplicationException("Process suspending failed: " + p.Id); } Clean(); result = IDL.InstantLoad(dat, dat.Length, p.Id, (DataType)comboBox_DataType.SelectedIndex, comboBox_DataType.SelectedIndex == 0 ? comboBox_ObjId.SelectedIndex : comboBox_DataType.SelectedIndex == 1 ? (-1) : // not to be used comboBox_BgId.SelectedIndex, comboBox_DataType.SelectedIndex == 0 ? (ObjectType)comboBox_ObjType.SelectedIndex : ObjectType.Invalid, this.Handle, logFunc); } finally { IDL.SuspendThreadList(resume, threads.Length, 0); if (result == 0) { label_Result.Text = "Successful"; //SetForegroundWindow(new HandleRef(p, p.MainWindowHandle)); //this.Close(); } else if (result == 1) { label_Result.Text = "Successful (warnings)"; StepCaret(); } else { label_Result.Text = "Error code: " + result; StepCaret(); } } } catch (ApplicationException ex) { MessageBox.Show(ex.ToString(), "Instant Data Loading Error"); } catch (Exception ex) { mainForm.formEventLog.Error(ex, "Instant Data Loading Error"); } }