2010-11-25 28 views
7

我是completely stuck評估需要一個線程臨時運行。使用觀察窗口執行評估

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.

是什麼意思:當試圖運行在VS 2010中的即時窗口的方法我測試MetaTrader API和得到下一個錯誤?它可能是因爲運行時版本差異(api 2.0,app 4.0)而發生的嗎?

回答

0

這是因爲服務器運行在.NET 2.0和客戶端(通過.NET Remoting) - 在.NET 4.0下。

將客戶端切換到.NET 2.0/3.5解決了該問題。

4

我相信錯誤意味着你正在嘗試執行的方法是產生一個線程。但是,由於程序處於「中斷」模式,因此無法運行。爲了避免死鎖(方法將永遠等待一個不會運行的線程),Visual Studio會殺死所有派生的線程。

我的建議是將調用轉移到程序中,並使用一些其他方法來執行它。

+0

聽起來很有希望,但我做了一個測試,發現:只有當應用程序的目標是4.0時纔會發生,沒有2.0/3.5的情況!怎麼會這樣?不同的線程/線程調試模型? – abatishchev 2010-11-26 06:58:35

+0

可能是。老實說,我對VS如何調試.NET運行時知之甚少。也許這個線程的情況在3.5中是允許的,但是無論什麼原因在4.0中被認爲是危險的? *聳肩*對不起,我不能更有幫助... – 2010-11-26 11:25:33

+0

無論如何感謝有趣的假設和建議! :) – abatishchev 2010-11-26 20:12:36

-1

不刪除其中將包含信息,如遵循的app.config:

<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> 
6

我相信你是通過即時窗口調用該方法最終調用Debugger.NotifyOfCrossThreadDependency。此方法僅在.NET 4.0中引入,因此使用較舊版本的運行時時,問題不會再現。 This blog post詳細解釋NotifyOfCrossThreadDependency,但其要點是它導致Watch窗口顯示Refresh按鈕,在評估發生之前必須按下該按鈕。但是,如果通過立即窗口進行評估,則會得到「評估需要臨時運行的線程。使用」觀察「窗口執行評估」錯誤。

下面是重現此錯誤的示例屬性:

public int CauseError 
    { 
     get 
     {     
      Debugger.NotifyOfCrossThreadDependency(); 
      return 5; 
     } 
    } 
-2

關閉你的VS和重建你的應用程序將幫助你。