• <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)論

            閱讀排行榜

            久久久久久综合一区中文字幕| 91久久精一区二区三区大全| 亚洲国产精品久久| 亚洲AV无码久久精品成人| 亚洲国产精品成人AV无码久久综合影院 | 亚洲欧洲精品成人久久曰影片| 99re这里只有精品热久久| 欧美一区二区三区久久综| 亚洲国产另类久久久精品小说| 国产精品一区二区久久精品涩爱| 欧美激情精品久久久久久久九九九| 久久免费视频观看| 99国内精品久久久久久久 | 亚洲狠狠久久综合一区77777| 东京热TOKYO综合久久精品| 久久久久久国产精品无码超碰| 久久亚洲精品成人av无码网站| 伊人久久大香线蕉综合Av| 久久久久亚洲av综合波多野结衣 | 亚洲精品高清久久| 97精品国产97久久久久久免费 | 亚洲人AV永久一区二区三区久久 | 久久久久波多野结衣高潮| 久久精品国产99久久久古代| 亚洲中文字幕无码久久综合网| 新狼窝色AV性久久久久久| 国产V综合V亚洲欧美久久| 热99re久久国超精品首页| 久久av高潮av无码av喷吹| 伊人久久国产免费观看视频| 性欧美丰满熟妇XXXX性久久久| a高清免费毛片久久| 久久涩综合| 久久亚洲精品国产精品| 久久国产精品免费一区二区三区| 香蕉久久永久视频| 国产∨亚洲V天堂无码久久久| 精品欧美一区二区三区久久久 | 久久66热人妻偷产精品9| 九九久久精品国产| 久久久无码精品亚洲日韩蜜臀浪潮|