Как я запускаю приложение один от другого в C#?

James Padolsey создал замечательный фильтр , который позволяет regex использоваться для выбора.

Говорят, что у Вас есть следующий div:

Padolsey :regex фильтр может выбрать его как так:

$("div:regex(class, .*sd.*)")

кроме того, проверьте официальная документация относительно селекторов .

21
задан Peter Mortensen 23 March 2010 в 18:55
поделиться

4 ответа

You can use .NET's Process Class to start a process as other people described. Then the question is when to call.

In most cases, using either Form.Closing or Form.Closed event seems to be an easy choice.

However, if someone else can handle the event and can set CancelEventArgs.Cancel to true, this may not be the right place to do this. Also, Form.Closing and Form.Closed events will not be raised when Application.Exit() is called. I am not sure whether either of events will be raised if any unhandled exceptions occur. (Also, you have to decide whether you want to launch the second application in case of Application.Exit() or any unhandled exception).

If you really want to make sure the second application (App2) launches after the first application (App1) exited, you can play a trick:

  1. Create a separate application (App0)
  2. App0 launches App1
  3. App0 waits for App1 to exit with Process.WaitExit()
  4. App0 launches App2 and exits itself

The sample console app attached below shows a very simple case: my sample app launches the notepad first. Then, when the notepad exits, it launches mspaint and exits itself.

If you want to hide the console, you can simply set the 'Output Type' property from 'Console Application' to 'Windows Application' under 'Application' tab of Project Property.

Sample code:

using System;
using System.Diagnostics;

namespace ProcessExitSample
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {

                Process firstProc = new Process();
                firstProc.StartInfo.FileName = "notepad.exe";
                firstProc.EnableRaisingEvents = true;

                firstProc.Start();

                firstProc.WaitForExit();

                //You may want to perform different actions depending on the exit code.
                Console.WriteLine("First process exited: " + firstProc.ExitCode);

                Process secondProc = new Process();
                secondProc.StartInfo.FileName = "mspaint.exe";
                secondProc.Start();                

            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred!!!: " + ex.Message);
                return;
            }
        }
    }
}
17
ответ дан 29 November 2019 в 20:43
поделиться

Вы можете просто выполнить оболочку это, поэтому, когда вы собираетесь выйти из первого приложения, просто запустите второе приложение через:

System.Diagnostics.Process.Start(@"PATH\NAME.EXE");
3
ответ дан 29 November 2019 в 20:43
поделиться

Использовать класс .NET Process .

1
ответ дан 29 November 2019 в 20:43
поделиться

Используйте класс процесса , когда закрываете свое первое приложение.

var p = new Process();
p.StartInfo.FileName   = "notepad.exe";  // just for example, you can use yours.
p.Start();
18
ответ дан 29 November 2019 в 20:43
поделиться
Другие вопросы по тегам:

Похожие вопросы: