private void RunGams() { MethodInvoker action = delegate { bu_run.Enabled = false; bu_close.Enabled = false; bu_cancel.Enabled = true; }; this.BeginInvoke(action); TextBoxBaseWriter tbw = new TextBoxBaseWriter(this.richTextBox1, this); GAMSWorkspace ws = new GAMSWorkspace(); ws.GamsLib("lop"); currentJob = ws.AddJobFromFile("lop.gms"); GAMSOptions opt = ws.AddOptions(); opt.AllModelTypes = "bdmlp"; opt.SolveLink = GAMSOptions.ESolveLink.CallModule; try { currentJob.Run(opt, tbw); } catch (GAMSException e) { action = delegate { richTextBox1.AppendText(e.Message); }; } action = delegate { bu_run.Enabled = true; bu_close.Enabled = true; bu_cancel.Enabled = false; }; this.BeginInvoke(action); }