private bool ProcessJob(string msg, ICompilerOutput output) { bool result = false; Compiler compiler = null; CommandLineOptions options = null; bool freeCompiler = false; string compilerId = null; try { XmlSerializer s = new XmlSerializer(typeof(CommandLineOptions)); options = (CommandLineOptions)s.Deserialize(new StringReader(msg)); bool retry = true; bool masterCreated = false; if (options.compilerId == null) { var pair = GetFreeCompiler(); compiler = pair.Item2; compilerId = pair.Item1; freeCompiler = true; } else { // the givein compilerId belongs to our client, so we can safely use it. lock (compilerlock) { compilerId = options.compilerId; compiler = compilerBusy[options.compilerId]; } } while (retry) { retry = false; try { if (options.inputFileNames == null) { // this is odd, compile will fail, but this stops the Debug output from crashing. options.inputFileNames = new List <string>(); } if (options.compilerOutput == CompilerOutput.Link) { DebugWriteLine("Linking: " + string.Join(", ", options.inputFileNames)); result = compiler.Link(output, options); } else { DebugWriteLine("Compiling: " + options.compilerOutput + ", " + string.Join(", ", options.inputFileNames)); result = compiler.Compile(output, options); } } catch (Exception ex) { result = false; if (!masterCreated) { // sometimes the compiler gets out of whack, and rebuilding it solves the problem. masterCreated = true; compiler = RebuildCompiler(compiler, compilerId); retry = true; } else { output.WriteMessage("Compile failed: " + ex.ToString(), SeverityKind.Error); } } } } catch (Exception ex) { result = false; if (output != null) { output.WriteMessage("internal error: " + ex.ToString(), SeverityKind.Error); } } finally { if (freeCompiler) { if (compiler != null) { FreeCompiler(compiler, compilerId); } } } try { if (options != null) { DebugWriteLine("Finished: " + options.compilerOutput + ", " + string.Join(", ", options.inputFileNames) + ", result=" + result); } } catch (Exception ex) { DebugWriteLine("Internal Error: " + ex.ToString()); } return(result); }