Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.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# 为什么当我使用process.WaitForInputIdle时进程总是不空闲?_C# - Fatal编程技术网

C# 为什么当我使用process.WaitForInputIdle时进程总是不空闲?

C# 为什么当我使用process.WaitForInputIdle时进程总是不空闲?,c#,C#,我想用C#将一些应用程序带到前端,我在SetForegroundWindow之前使用WaitForInputdle,并且WaitForInputdle总是阻塞,如果我设置超时参数,它将返回false。这是我的密码: 使用系统; 使用系统诊断; 使用System.Runtime.InteropServices; 名称空间AppToFront { 班级计划 { [DllImport(“USER32.DLL”)] 静态外部布尔设置窗口布局(IntPtr hWnd,[In]参考窗口布局lpwndpl);

我想用C#将一些应用程序带到前端,我在
SetForegroundWindow
之前使用
WaitForInputdle
,并且
WaitForInputdle
总是阻塞,如果我设置超时参数,它将返回false。这是我的密码:

使用系统;
使用系统诊断;
使用System.Runtime.InteropServices;
名称空间AppToFront
{
班级计划
{
[DllImport(“USER32.DLL”)]
静态外部布尔设置窗口布局(IntPtr hWnd,[In]参考窗口布局lpwndpl);
[DllImport(“USER32.DLL”)]
静态外部bool setforegroundindow(IntPtr hWnd);
[DllImport(“user32.dll”)]
[返回:Marshallas(UnmanagedType.Bool)]
静态外部布尔GetWindowPlacement(IntPtr hWnd,ref WINDOWPLACEMENT lpwndpl);
//窗口放置结构的定义
[StructLayout(LayoutKind.Sequential)]
私有结构窗口放置
{
公共整数长度;
公共国旗;
公共int showCmd;
公共系统图点位置;
公共系统.Drawing.Point ptMaxPosition;
公共系统.Drawing.Rectangle位置;
}
//不同窗口放置常量的定义
const UInt32 SW_HIDE=0;
const UInt32 SW_SHOWNORMAL=1;
const UInt32 SW_NORMAL=1;
const UInt32 SW_=2;
const UInt32 SW_showmized=3;
const UInt32 SW_最大化=3;
const UInt32 SW_shownoactive=4;
const UInt32 SW_SHOW=5;
const UInt32 SW_MINIMIZE=6;
const UInt32 SW_showminoactive=7;
const UInt32 SW_SHOWNA=8;
const UInt32 SW_RESTORE=9;
公共静态void BringFont(字符串名称)
{
//检查应用程序是否正在运行
尝试
{
Process=Process.getProcessByName(名称)[0];
if(进程!=null)
{
process.Refresh();
bool status=process.WaitForInputIdle(1000);
控制台写入线(状态);
IntPtr s=process.MainWindowHandle;
WINDOWPLACEMENT参数=新建WINDOWPLACEMENT();
param.length=Marshal.SizeOf(typeof(WINDOWPLACEMENT));
GetWindowPlacement(s,参考参数);
Console.WriteLine(参数showCmd);
如果(param.showCmd==1 | | param.showCmd==3)
{
SetforeGroundindow(s);
}
其他的
{
param.showCmd=1;
设置窗口位置(s,参考参数);
}
}
}
捕获(异常exc)
{
Console.WriteLine(“错误:应用程序未运行!\n异常:+exc.Message”);
Console.ReadKey();
返回;
}
}
静态void Main(字符串[]参数)
{
布林格丰(“铬”);
控制台写入线(“开始”);
}
}
}

ok,这是因为我在使用
process process=process.getProcessByName(name)[0]时遇到了错误的process好,这是因为我在使用
process=process.getProcessByName(name)[0]时遇到了错误进程