Process.Start()后,Process的UI不可见

时间:2016-02-22 10:50:38

标签: c# wcf

我制作了一个WCF服务,它包含一个方法 string SaveVideoInformation()

此方法的目的是在未运行的情况下运行进程。 以下是该方法的代码。

 public string SaveVideoInformation(string ID, string videoName)
    {
        string Result = null;
        try
        {
            Result = Insert(ID, videoName);
            Process[] pname = Process.GetProcessesByName("AutoRunVideoWaterMarkingTook");
            if (pname.Length == 0)
            {
                Result += " | Trying to run Process";
                try
                {
                    Process process = Process.Start(@"~\Debug\AutoRunVideoWaterMarkingTook.exe");
                    Result += " | Process Ran Successfully";
                }
                catch (Exception ex)
                {
                    Result += " | Exception While Running the process";
                    throw new Exception("Unable to start Process);
                }
            }
            else
            {
                Result += "|Process Already Running";
            }
        }
        catch (Exception ex)
        {
            Result = "Not Done," + ex.Message;
        }
        return Result;
    }

我面临的问题是当我从Windows表单工具应用程序调用此方法时,它运行成功,我可以看到UI。

但是当我从Windows服务调用此方法时,Process Starts但其UI不可见。

1 个答案:

答案 0 :(得分:1)

这很可能是因为您的Windows服务未处于用户交互模式。

您必须在“服务”面板中启用此功能,如this blog中所述:检查服务属性Allow service to interact with desktop页面中的Log On

另请阅读Microsofts recommendations on user interactive services