Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluation requires a thread to run temporarily. Use the Watch window to perform the evaluation

I'm completely stuck. I'm testing MetaTrader API and getting next error when tries to run a method in the Immediate Window of VS 2010:

A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll

A first chance exception of type 'System.Threading.ThreadAbortException' occurred in System.Runtime.Remoting.dll

Evaluation requires a thread to run temporarily. Use the Watch window to perform the evaluation.

What does it mean? Can it happens because of runtime versions difference (api 2.0, app 4.0)?

like image 541
abatishchev Avatar asked Nov 25 '10 20:11

abatishchev


2 Answers

I believe the method you are calling through the Immediate Window ends up calling Debugger.NotifyOfCrossThreadDependency. This method was only introduced in .NET 4.0, so it makes sense that the problem won't reproduce itself when using an older version of the runtime. This blog post explains NotifyOfCrossThreadDependency in detail, but the gist of it is that it causes the Watch window to show a Refresh button which must be pressed before the evaluation occurs. If it is evaluated through the Immediate Window, though, you get the "Evaluation requires a thread to run temporarily. Use the Watch window to perform the evaluation" error.

Here's an example property that reproduces this error:

    public int CauseError
    {
        get 
        {                
            Debugger.NotifyOfCrossThreadDependency();
            return 5;
        }
    }
like image 89
Omer Raviv Avatar answered Sep 20 '22 14:09

Omer Raviv


I believe that error means that the method you are trying to execute is spawning a thread. However, since the program is in Break mode, it can't run. To avoid a deadlock (where the method will wait forever for a thread that won't run), Visual Studio kills any spawned threads.

My suggestion is to move the call into the program, and use some other means to execute it.

like image 22
Mike Caron Avatar answered Sep 16 '22 14:09

Mike Caron