Evaluator fails if initialized from ThreadPool

50 views
Skip to first unread message

rav...@gmail.com

unread,
Apr 29, 2013, 1:31:16 AM4/29/13
to cs-s...@googlegroups.com
Hi,

Evaluator fails or hangs if it is first run from ThreadPool. If it is initialized from main thread then it succeed in ThreadPool as well.

Strangely, when single-stepping through code an I get "Exception of type 'System.Threading.ThreadAbortException' was thrown" followed
by "The type initializer for 'Mono.CSharp.InteractiveBase' threw an exception.".

However, without debugging Evaluator simply hangs in ThreadPool.

Sample code:

    class Program
    {
        static void Main(string[] args)
        {
            // If uncommented then both tests succeed
            // test(null);
            ThreadPool.QueueUserWorkItem(test);
            Console.WriteLine("Press any key to quit...");
            Console.ReadKey();
        }

        private static void test(object state)
        {
            try
            {
                Console.WriteLine("Starting evaluation. ThreadPool: {0}", Thread.CurrentThread.IsThreadPoolThread);
                int result = (int)CSScript.Evaluator.Evaluate("1 + 2;");
                Console.WriteLine("Got result: {0}. ThreadPool: {1}", result, Thread.CurrentThread.IsThreadPoolThread);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: {0}. ThreadPool: {1}", ex.Message, Thread.CurrentThread.IsThreadPoolThread);
            }
        }
    }


Any idea?

Thanks for great work,
Ron

Oleg Shilo

unread,
Apr 29, 2013, 7:48:35 AM4/29/13
to cs-s...@googlegroups.com
I cannot reproduce the problem. The following code works just fine:
        Action test = () =>
            {
                var result = CSScript.Evaluator.Evaluate("1+2;");
                Console.WriteLine("{0} thread: {1}", 
                    Thread.CurrentThread.IsThreadPoolThread ? "Background" : "Main", 
                    result);
            };
 
        //test();
        ThreadPool.QueueUserWorkItem(x=>test());
 
        Console.ReadLine();
Is there anything special about your environment?
Oleg



--
You received this message because you are subscribed to the Google Groups "CS-Script" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cs-script+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

rav...@gmail.com

unread,
Apr 29, 2013, 10:27:18 AM4/29/13
to cs-s...@googlegroups.com, osh...@gmail.com
Oleg,

This is really strange. Your code works for me, but my code still doesn't. I'm using Windows 7, VS2012.
Please try and run my code exactly as below. It always hangs for me.

Thanks,
Ron


using CSScriptLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ThreadScriptTest
{

Oleg Shilo

unread,
Apr 29, 2013, 8:38:41 PM4/29/13
to cs-s...@googlegroups.com
I actually started with your sample. You can collect it (VS2012 project) here https://dl.dropboxusercontent.com/u/2192462/Support/ravriel/ravriel.7z
It also works as expected. 
 
In my case it is Win8/VS2012.

In any case there is something peculiar with the Mono.CSharp static initialization. I had a very quick look in Reflector and cannot see anything obvious. You can probably reproduce the problem without CS-Script but Mono.CSharp only. Reflector VS extension would be great for this sort of investigation as it would decompile Mono.CSharp.dll on fly and debugger will pinpoint to the cause of the problem.

Cheers,
Oleg
Reply all
Reply to author
Forward
0 new messages