Wednesday, 18 September 2013

Sleeping thread when using Mono Evaluator

Sleeping thread when using Mono Evaluator

I'm doing on the fly compilation using Mono Evaluator, almost everything
is ok but I'm having an issue with Sleep in side evaluated code.
here is piece of sample code:
public class TestClass
{
public static void TestMethod()
{
System.Threading.Thread.Sleep(5000);
Console.WriteLine("Test finish."));
}
}
and here is the code I'm using to execute C# on the fly using Mono Evaluator:
var reportWriter = new StringWriter();
var consoleReport = new ConsoleReportPrinter(reportWriter);
var context = new CompilerContext(new CompilerSettings(), consoleReport);
var eval = new Evaluator(context);
eval.Run(code);
eval.Run(@"
var output = new System.IO.StringWriter();
Console.SetOut(output);
TestClass.TestMethod();");
Then doing:
string result = (string)eval.Evaluate("output.ToString();");
i'm having in "result" the return of executed code. If I dont use Sleep()
inside executed code, everything is ok. But when I do Sleep() then the
line to get "result" is executed without waiting the 5000 miliseconds.
I'm expecting that the code passed to Evaluator.Run sleep as it is
sleeping inside. why it is not happening ?
How can I achive the wait for executed code finish before evaluate result ??
thanks a lot

No comments:

Post a Comment