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

流过昼夜 提交于 2019-11-28 12:03:14

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

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.

That's because the server is running under .NET 2.0 and a client (thru .NET Remoting) - under .NET 4.0.

Switching client to .NET 2.0/3.5 fixed the problem.

do not remove the app.config which will contain information like follows:

<configuration>
  <configSections>
    <sectionGroup name="userSettings" 
                  type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section 
               name="MySolution.Properties.Settings"
               type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
               allowExeDefinition="MachineToLocalUser" 
               requirePermission="false" />
    </sectionGroup>
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!