Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 确定另一进程中的UI线程_C#_User Interface - Fatal编程技术网

C# 确定另一进程中的UI线程

C# 确定另一进程中的UI线程,c#,user-interface,C#,User Interface,在C#中是否可以确定由我的进程打开的另一个应用程序中的哪个线程是UI线程?@HansPassant已经: 你是如何打开另一个应用程序的?还有:为什么?我用“Process.Start”打开了它。为什么?我需要检查进程是否被卡住(即未处理其消息队列中的消息)。我尝试了进程的“IsResponding”属性,但它始终是“true”。另一个应用程序是否受您的源代码控制? using System.Diagnostics; ... public static ProcessThread GetUIThr

在C#中是否可以确定由我的进程打开的另一个应用程序中的哪个线程是UI线程?

@HansPassant已经:


你是如何打开另一个应用程序的?还有:为什么?我用“Process.Start”打开了它。为什么?我需要检查进程是否被卡住(即未处理其消息队列中的消息)。我尝试了进程的“IsResponding”属性,但它始终是“true”。另一个应用程序是否受您的源代码控制?
using System.Diagnostics;
...
public static ProcessThread GetUIThread(Process proc) {
  if (proc.MainWindowHandle == null) return null;
  int id = GetWindowThreadProcessId(proc.MainWindowHandle, IntPtr.Zero);
  foreach (ProcessThread pt in proc.Threads)
    if (pt.Id == id) return pt;
  return null;
}

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int GetWindowThreadProcessId(IntPtr hWnd, IntPtr procid);