Debugger.CurrentThread 属性

设置或获取正在调试的当前线程。

命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)

语法

声明
Property CurrentThread As Thread
Thread CurrentThread { get; set; }
property Thread^ CurrentThread {
    Thread^ get ();
    void set (Thread^ value);
}
abstract CurrentThread : Thread with get, set
function get CurrentThread () : Thread 
function set CurrentThread (value : Thread)

属性值

类型:EnvDTE.Thread
一个 Thread 对象。

备注

CurrentThread 设置或返回当前正在调试的 Thread 对象。

示例

下面的示例演示如何使用 CurrentThread 属性。

测试此属性:

  1. 在目标应用程序中设置一个断点。 运行外接程序。

    当前线程为空。

  2. 在目标应用程序中设置一个断点。 以调试模式运行目标应用程序。 当此应用程序停在该断点处时,运行外接程序。

    结果为:当前线程为非空。

public static void CurrentThread(DTE dte)
{
    // Setup the debug Output window.
    Window w = (Window)dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
    w.Visible = true;
    OutputWindow ow = (OutputWindow)w.Object;
    OutputWindowPane owp = ow.OutputWindowPanes.Add("Current Thread Test");
    owp.Activate();

    owp.OutputString("Current Thread Info: ");
    EnvDTE.Thread thread = dte.Debugger.CurrentThread;

    if(thread == null)
        owp.OutputString("No program is being debugged");
    else
        foreach(EnvDTE.StackFrame sf in thread.StackFrames)
            owp.OutputString("\nStack Frame: Function " + sf.FunctionName + 
                             " returns type " + sf.ReturnType);
}
Shared Sub CurrentThread(ByRef dte As EnvDTE.DTE)
    Dim str As String
    Dim thread As EnvDTE.Thread = dte.Debugger.CurrentThread
    If thread Is Nothing Then
        MessageBox.Show("No program is being debugged.", _
                        "Debugger Test - Current Thread Info")
    Else
        For Each sf As EnvDTE.StackFrame In thread.StackFrames
            str += vbCrLf + "Stack Frame: Function " + _
                   sf.FunctionName.ToString() + " returns type " + _
                   sf.ReturnType
        Next
        MessageBox.Show(str, "Debugger Test - Current Thread Info")
    End If
End Sub

.NET Framework 安全性

请参阅

参考

Debugger 接口

EnvDTE 命名空间