它会启动一个外部进程后,屏幕保护程序不会重新启动 [英] screensaver does not restart after it launches an external process

查看:164
本文介绍了它会启动一个外部进程后,屏幕保护程序不会重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我采取一个屏幕保护程序重新启动后台应用程序。我需要的是重新启动Firefox在Windows亭重置主页。我想与一个屏幕保护程序做到这一点。我使用的语言是C#。

I'm implementing a screensaver to restart a background application. My need is to restart firefox to reset the home page in a windows kiosk. I would like to do this with a Screen Saver. The language I use is C#.

中的代码也不是那么复杂,是一种副本,并从

The code is not so complex and is a sort of copy and paste from

的http:// MSDN。 microsoft.com/en-us/library/windows/desktop/ms686421(v=vs.85).aspx

http://www.harding.edu/fmccown/屏保/ screensaver.html

应该以这种方式工作:屏幕保护程序启动后,再经过10秒。杀死应用程序(如果它存在),然后,10秒后。它再次重新启动应用程序。所有的屏幕保护程序后退出(也就是驱动这个定时器)。

It should work in this manner: the screensaver starts, then after 10 sec. kills the application (if it exists) and then, after 10 sec. again it restarts the application. After all the screensaver quit (there is a timer that drives this).

的问题是,通过屏幕保护程序启动的过程中有一种链接打死屏保, 因为直到用户不杀应用程序,屏幕保护程序不会重新启动

The problem is that the process started by the screensaver has a sort of link to the killed screensaver, because until the user doesn't kill the application, the screensaver doesn't restart!

我用这个功能来重新启动应用程序:<! / p>

I use this function to restart the application:

public static void StartAProcess(string executableName)
{
    //Process.Start(new ProcessStartInfo(executableName));

    RunThread ext = new RunThread();
    Thread t = new Thread(new ParameterizedThreadStart(ext.OpenProcess));
    t.Start(executableName.ToString());
}


public class RunThread
{
    public void OpenProcess(object executableName)
    {
        ProcessStartInfo si = new ProcessStartInfo();
        si.UseShellExecute = true;
        si.FileName = (string) executableName;
        Process proc = Process.Start(si);
        ---> if (null != proc)
             proc.WaitForExit();   // Block until exit**
    }
}



该行为是不同的根据不同的操作系统和WaitForExit指令上:

The behaviour is different depending on the OS and the WaitForExit instruction:


  • 与WaitForExit :在七,Vista和XP,后应用程序的启动,屏幕保护程序不会重新启动;

  • 无WaitForExit :在Vista /七同PREC点,在Windows XP中,当屏幕保护程序退出它杀死的应用程序呢!

  • with WaitForExit: on Seven, Vista and XP, after the start of the application, the screensaver doesn't restart;
  • without WaitForExit: on Vista/Seven the same of prec point, on Windows XP when the screensaver exit it kills the application too!

推荐答案

视窗保护自己从你想要的行为通过在作业对象跑跑屏幕保护程序代码防止任何进程从工作转义开始。这样,屏幕保护程序不能留下任何的进程运行时,用户不希望的。 Windows将要么终止工作(以及所有的进程内就开始),当屏幕保护程序终止(操作系统),或者它会等到作业对象本身终止(即作业中的每个进程终止)。

Windows protects itself from the behavior you're trying to code by running the screen saver in a job object that prevents any process started from "escaping" from the job. That way the screensaver can't leave any processes running when the user doesn't expect. Windows will either terminate the job (and thus all of the processes started within it) when the screensaver process terminates (WinXP) or it will wait until the the job object itself terminates (i.e. every process in the job terminates).

据你为什么用这个屏幕保护程序尚不清楚。我可能要么使用在启动时或服务做这样的事情上运行的程序。

It's not clear why you're using a screensaver for this. I probably would either use a program that runs on startup or a service to do something like this.

无论如何,如果你必须使用屏幕保护程序,你必须找到一个方法来创建你的工作对象外的过程。有一点要考虑的是创建Win32_Process类的方法

Regardless, if you have to use a screensaver, you have to find a way to create a process from outside your job object. One thing to consider is the Create method of the Win32_Process Class.

根据您的指示,这听起来你想要当用户重启浏览器,如您有应用程序的一个网吧的类型左亭。在这种情况下,我会推荐别的东西完全:

Based on your indication that you want to restart Firefox, it sounds like you have an Internet kiosk type of application where you want to restart the browser when the user has left the kiosk. In that case I would recommend something else entirely:


  • 创建启动火狐,等待其退出,然后重新启动程序它,都在一个无限循环运行。运行使用某种自动运行般的机制这一计划。

  • Create a program that starts Firefox, waits for it to exit, then restarts it, all running in an infinite loop. Run this program using some sort of AutoRuns-like mechanism.

请您简单的屏幕保护杀Firefox和退出。当屏幕保护程序激活,它会杀死Firefox和退出,从而导致循环程序重新启动它。

Make your screensaver simply kill Firefox and exit. When the screensaver activates, it will kill Firefox and exit, causing the looping program to restart it.

这篇关于它会启动一个外部进程后,屏幕保护程序不会重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆