Loading...
Searching...
No Matches
Form1.cs
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using System.Runtime.InteropServices;
10using System.Diagnostics;
11using System.Threading.Tasks;
12using GAMS;
13using System.IO;
14
15namespace InterruptGui
16{
25 public partial class Form1 : Form
26 {
27 GAMSJob currentJob = null;
28 public Form1()
29 {
30 InitializeComponent();
31 this.ControlBox = false;
32 }
33
34 private void RunGams()
35 {
36 MethodInvoker action = delegate
37 {
38 bu_run.Enabled = false;
39 bu_close.Enabled = false;
40 bu_cancel.Enabled = true;
41 richTextBox1.Clear();
42 };
43 this.BeginInvoke(action);
44
45 TextBoxBaseWriter tbw = new TextBoxBaseWriter(this.richTextBox1, this);
46
48 ws.GamsLib("lop");
49 currentJob = ws.AddJobFromFile("lop.gms");
50 GAMSOptions opt = ws.AddOptions();
51 opt.AllModelTypes = "soplex";
52 opt.SolveLink = GAMSOptions.ESolveLink.CallModule;
53
54 try
55 {
56 currentJob.Run(opt, tbw);
57 }
58 catch (GAMSException e)
59 {
60 action = delegate
61 {
62 richTextBox1.AppendText(e.Message);
63 };
64 }
65
66 action = delegate
67 {
68 bu_run.Enabled = true;
69 bu_close.Enabled = true;
70 bu_cancel.Enabled = false;
71 };
72 this.BeginInvoke(action);
73 }
74
75 private void bu_run_Click(object sender, EventArgs e)
76 {
77 Task.Factory.StartNew(() => RunGams());
78 }
79
80 private void bu_cancel_Click(object sender, EventArgs e)
81 {
82 currentJob.Interrupt();
83 }
84
85 private void bu_close_Click(object sender, EventArgs e)
86 {
87 Close();
88 }
89 }
90}
bool Interrupt()
void Run(GAMSOptions gamsOptions=null, GAMSCheckpoint checkpoint=null, TextWriter output=null, Boolean createOutDB=true)
void GamsLib(string model)
GAMSJob AddJobFromFile(string fileName, GAMSCheckpoint checkpoint=null, string jobName=null)
GAMSOptions AddOptions(GAMSOptions optFrom=null)
This small example demonstrates how to run a GAMS model in a graphical user interface....
Definition: Form1.cs:26