有一件事我一直注意到的是,從即時窗口任何電話至少包含一個電話從以下命名空間起源:
Microsoft.VisualStudio.HostingProcess
所以,如果你有,說:
public static string DumpStack()
{
return new StackTrace().ToString();
}
你會看到類似的東西:
at ConsoleApplication1.Program.DumpStack()
at ConsoleApplication1.Program.Main(String[] args)
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
當你等待有人回答,試着玩[StackTrace](htt p://msdn.microsoft.com/en-us/library/system.diagnostics.stacktrace(v = vs.100).aspx)類,並查看是否可以從調用的調用堆棧中得知。它可能很明顯是來自調試器組件。 – HABO
http://stackoverflow.com/questions/2188201/is-there-a-way-to-detect-if-a-debugger-is-attached-to-a-process-from-c-sharp你可以試試這個 –
@Paul,謝謝,但那個系統使用了Debugger.IsAttached,我指定的不能在這裏工作,因爲這個代碼也會在我調試庫本身時運行... – Joe