static void Main(string[] args) { GAMSWorkspace gmsWS; if (Environment.GetCommandLineArgs().Length > 1) { gmsWS = new GAMSWorkspace(systemDirectory: Environment.GetCommandLineArgs()[1]); } else { gmsWS = new GAMSWorkspace(); } // create a GAMSDatabase for the results GAMSDatabase resultDB = gmsWS.AddDatabase(); resultDB.AddParameter("objrep", 1, "Objective value"); resultDB.AddSet("supplyMap", 3, "Supply connection with level"); int status = 1; try { // run multiple parallel jobs Object dbLock = new Object(); System.Threading.Tasks.Parallel.For(10, 22, delegate(int i) { SolveWarehouse(gmsWS, i, resultDB, dbLock); }); // export the result database to a GDX file resultDB.Export("\\tmp\\result.gdx"); status = 0; } catch (GAMSException ex) { Console.WriteLine("GAMSException occured: " + ex.Message); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { resultDB.Dispose(); } Environment.ExitCode = status; }