• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            C++ Programmer's Cookbook

            {C++ 基礎(chǔ)} {C++ 高級(jí)} {C#界面,C++核心算法} {設(shè)計(jì)模式} {C#基礎(chǔ)}

            進(jìn)程 Process的使用

            1 Process?
            ? 簡(jiǎn)單實(shí)例:

            // ?Execute?notepad.exe?with?no?command-line?arguments.
            Process.Start( " notepad.exe " );

            // ?Execute?notepad.exe?passing?the?name?of?the?file?to?open?as?a?
            // ?command-line?argument.
            Process.Start( " notepad.exe " ,? " SomeFile.txt " );

            Properties of the ProcessStartInfo Class

            Property

            Description

            Arguments

            The command-line arguments to pass to the new process.

            ErrorDialog

            If Process.Start can't start the specified process, it will throw a System.ComponentModel.Win32Exception. If ErrorDialog is true, Start displays an error dialog to the user before throwing the exception.

            FileName

            The name of the application to start. You can also specify any type of file for which you have configured an application association. For example, you could specify a file with a .doc or .xls extension, which would cause Microsoft Word or Microsoft Excel to run.

            WindowStyle

            A member of the System.Diagnostics.ProcessWindowStyle enumeration, which controls how the window is displayed. Valid values include Hidden, Maximized, Minimized, and Normal.

            WorkingDirectory

            The fully qualified name of the initial directory for the new process.


            進(jìn)程的啟動(dòng):

            The following example uses Process to execute Notepad in a maximized window and open a file named C:\Temp\file.txt. After creation, the example calls the Process.WaitForExit method, which blocks the calling thread until a process terminates or a specified time-out expires.


            using?System;
            using?System.Diagnostics;

            public?class?StartProcessExample?{

            ????
            public?static?void?Main?()?{

            ????????
            //?Create?a?ProcessStartInfo?object?and?configure?it?with?the?
            ????????
            //?information?required?to?run?the?new?process.
            ????????ProcessStartInfo?startInfo?=?new?ProcessStartInfo();

            ????????startInfo.FileName?
            =?"notepad.exe";
            ????????startInfo.Arguments?
            =?"file.txt";
            ????????startInfo.WorkingDirectory?
            =?@"C:\Temp";
            ????????startInfo.WindowStyle?
            =?ProcessWindowStyle.Maximized;
            ????????startInfo.ErrorDialog?
            =?true;

            ????????
            //?Create?a?new?Process?object.
            ????????using?(Process?process?=?new?Process())?{

            ????????????
            //?Assign?the?ProcessStartInfo?to?the?Process.
            ????????????process.StartInfo?=?startInfo;

            ????????????
            try?{

            ????????????????
            //?Start?the?new?process.
            ????????????????process.Start();

            ????????????????
            //?Wait?for?the?new?process?to?terminate?before?exiting.
            ????????????????Console.WriteLine("Waiting?30?seconds?for?process?to"?+
            ????????????????????
            "?finish.");
            ????????????????process.WaitForExit(
            30000);

            ????????????}
            ?catch?(Exception?ex)?{

            ????????????????Console.WriteLine(
            "Could?not?start?process.");
            ????????????????Console.WriteLine(ex);
            ????????????}

            ????????}


            ????????
            //?Wait?to?continue.
            ????????Console.WriteLine("Main?method?complete.?Press?Enter.");
            ????????Console.ReadLine();
            ????}

            }


            進(jìn)程終止:
            Methods for Obtaining Process References

            Method

            Description

            GetCurrentProcess

            Returns a Process object representing the currently active process.

            GetProcessById

            Returns a Process object representing the process with the specified ID.

            GetProcesses

            Returns an array of Process objects representing all currently active processes.

            GetProcessesByName

            Returns an array of Process objects representing all currently active processes with a specified friendly name. The friendly name is the name of the executable excluding file extension or path; for example, notepad or calc.

            The following example starts a new instance of Notepad, waits five seconds, and then terminates the Notepad process. The example first tries to terminate the process using CloseMainWindow. If CloseMainWindow returns false, or the Notepad process is still running after CloseMainWindow is called, the example calls Kill and forces the Notepad process to terminate; you can force CloseMainWindow to return false by leaving the File Open dialog box open.

            using?System;
            using?System.Threading;
            using?System.Diagnostics;

            public?class?TerminateProcessExample?{

            ????
            public?static?void?Main?()?{

            ????????
            //?Create?a?new?Process?and?run?notepad.exe.
            ????????using?(Process?process?=?Process.Start("notepad.exe"))?{

            ????????????
            //?Wait?for?5?seconds?and?terminate?the?notepad?process.
            ????????????Console.WriteLine("Waiting?5?seconds?before?terminating"?+
            ????????????????
            "?notepad.exe.");
            ????????????Thread.Sleep(
            5000);

            ????????????
            //?Terminate?notepad?process.
            ????????????Console.WriteLine("Terminating?Notepad?with?CloseMainWindow.");

            ????????????
            //?Try?to?send?a?close?message?to?the?main?window.
            ????????????if?(!process.CloseMainWindow())?{

            ????????????????
            //?Close?message?did?not?get?sent?-?Kill?Notepad.
            ????????????????Console.WriteLine("CloseMainWindow?returned?false?-?"?+
            ????????????????????
            "?terminating?Notepad?with?Kill.");
            ????????????????process.Kill();

            ????????????}
            ?else?{

            ????????????????
            //?Close?message?sent?successfully;?wait?for?2?seconds
            ????????????????
            //?for?termination?confirmation?before?resorting?to?Kill.
            ????????????????if?(!process.WaitForExit(2000))?{

            ????????????????????Console.WriteLine(
            "CloseMainWindow?failed?to"?+
            ????????????????????????
            "?terminate?-?terminating?Notepad?with?Kill.");
            ????????????????????process.Kill();
            ????????????????}

            ????????????}

            ????????}


            ????????
            //?Wait?to?continue.
            ????????Console.WriteLine("Main?method?complete.?Press?Enter.");
            ????????Console.ReadLine();
            ????}

            }

            posted on 2006-04-20 19:11 夢(mèng)在天涯 閱讀(2267) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C#/.NET

            公告

            EMail:itech001#126.com

            導(dǎo)航

            統(tǒng)計(jì)

            • 隨筆 - 461
            • 文章 - 4
            • 評(píng)論 - 746
            • 引用 - 0

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1804303
            • 排名 - 5

            最新評(píng)論

            閱讀排行榜

            色综合久久无码中文字幕| 伊人久久大香线焦综合四虎| 四虎久久影院| 久久久久久亚洲Av无码精品专口| 国产91色综合久久免费| 久久AAAA片一区二区| 亚洲国产欧洲综合997久久| 很黄很污的网站久久mimi色| 熟妇人妻久久中文字幕| 久久久久国产日韩精品网站| 日韩乱码人妻无码中文字幕久久 | 国内精品久久久久影院优| 国产精品久久久天天影视香蕉 | 亚洲国产精品久久| 国产亚洲精品久久久久秋霞| 久久精品国产亚洲沈樵| 久久精品国产亚洲αv忘忧草| 91精品久久久久久无码| 国产69精品久久久久9999APGF| 久久久久久av无码免费看大片| 国内精品久久久久久99| 亚洲国产精品无码久久久秋霞2 | 久久精品国产亚洲AV嫖农村妇女| 91精品日韩人妻无码久久不卡| 久久99精品久久久久子伦| 97精品依人久久久大香线蕉97| 内射无码专区久久亚洲| 久久久久久毛片免费看| 久久久久无码精品| 蜜桃麻豆www久久国产精品| 久久久久亚洲AV成人网人人软件 | 国产精品美女久久久免费| 一本一道久久精品综合| 国产AⅤ精品一区二区三区久久| 国产精品久久久久9999高清| 久久久久无码精品国产| 成人妇女免费播放久久久| 久久精品国产亚洲AV大全| 久久se精品一区精品二区| 久久久久久久尹人综合网亚洲 | 精品久久久久国产免费|