Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

c# - 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)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...