Forum Discussion
FICO
6 years agoCommunity Manager
Redirect stream in C# with parallel (independant) mosel instances
I have written a c# method "MyMethod" solving a given mosel model and getting solution. At the beginning of "MyMethod", I have : var mosel = XPRM.Init();
mosel.SetDefaultStream(XPRMStreamType.F_...
FICO
6 years agoCommunity Manager
So you advice to create only one XPRM object and to share it between all the threads. Is this correct ?
But in this case, all the threads have to write log at the same place.
So a code where each thread writes a specific log file is not possible. For example :
Main method :
Parallel.For(0, 10, i =>
{
MyMethod(i);
});MyMethod(int i) :
XPRM mosel = XPRM.Init();
string fichierLog = Path.GetFullPath($@"LogMosel{i}.txt");
StreamWriter sw = new StreamWriter(fichierLog, false);
XPRMIOCallbackOutputText callback = (XPRMModel model, object obj, string line) =>
{
Console.Write(line);
sw.Write(line);
};
mosel.SetDefaultStream(XPRMStreamType.F_OUTPUT, mosel.CreateIOCallback(callback));
mosel.SetDefaultStream(XPRMStreamType.F_ERROR, mosel.CreateIOCallback(callback));