免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
C#進(jìn)程管理啟動(dòng)和停止

C#進(jìn)程的開始和結(jié)束,源碼如下,謝謝

轉(zhuǎn)載請(qǐng)注明出處http://www.cnblogs.com/minotmin/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
//引用命名空間
using System.Diagnostics;
using System.Threading;


namespace StartStopProcess
{
    public partial class Form1 : Form
    {
        int fileIndex;
        string fileName = "Notepad.exe";
        Process process1 = new Process();
        public Form1()
        {
            InitializeComponent();
            //以詳細(xì)列表方式顯示
            listView1.View = View.Details;
            //參數(shù)含義:列名稱,寬度(像素),水平對(duì)齊方式
            listView1.Columns.Add("進(jìn)程ID", 70, HorizontalAlignment.Left);
            listView1.Columns.Add("進(jìn)程名稱", 70, HorizontalAlignment.Left);
            listView1.Columns.Add("占用內(nèi)存", 70, HorizontalAlignment.Left);
            listView1.Columns.Add("啟動(dòng)時(shí)間", 70, HorizontalAlignment.Left);
            listView1.Columns.Add("文件名", 280, HorizontalAlignment.Left);
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            string argument = Application.StartupPath + "            if (File.Exists(argument)==false)
            {
                File.CreateText(argument);
            }
            //設(shè)置要啟動(dòng)的應(yīng)用程序名稱及參數(shù)
            ProcessStartInfo ps = new ProcessStartInfo(fileName, argument);
            ps.WindowStyle = ProcessWindowStyle.Normal;
            fileIndex++;
            Process p = new Process();
            p.StartInfo = ps;
            p.Start();
            //等待啟動(dòng)完成,否則獲取進(jìn)程信息可能會(huì)失敗
            p.WaitForInputIdle();
            RefreshListView();
        }

        private void buttonStop_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            //創(chuàng)建新的Process組件的數(shù)組,并將它們與指定的進(jìn)程名稱(Notepad)的所有進(jìn)程資源相關(guān)聯(lián).
            Process[] myprocesses;
            myprocesses = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(fileName));
            foreach (Process p in myprocesses)
            {
                //通過(guò)向進(jìn)程主窗口發(fā)送關(guān)閉消息達(dá)到關(guān)閉進(jìn)程的目的
                p.CloseMainWindow();
                //等待1000毫秒
                Thread.Sleep(1000);
                //釋放與此組件關(guān)聯(lián)的所有資源
                p.Close();
            }
            fileIndex = 0;
            RefreshListView();
            this.Cursor = Cursors.Default;
        }

        private void RefreshListView()
        {
            listView1.Items.Clear();
            //創(chuàng)建Process類型的數(shù)組,并將它們與系統(tǒng)內(nèi)所有進(jìn)程相關(guān)聯(lián)
            Process[] processes;
            processes = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(fileName));
            foreach (Process p in processes)
            {
                //將每個(gè)進(jìn)程的進(jìn)程名稱、占用的物理內(nèi)存以及進(jìn)程開始時(shí)間加入listView中
                ListViewItem item = new ListViewItem(
                    new string[]{
                        p.Id.ToString(),
                        p.ProcessName,
                        string.Format("{0} KB", p.PrivateMemorySize64/1024.0f),
                        string.Format("{0}",p.StartTime),
                        p.MainModule.FileName
                    });
                listView1.Items.Add(item);
            }
        }

        private void buttonRefresh_Click(object sender, EventArgs e)
        {
            RefreshListView();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
winform下用FileStream實(shí)現(xiàn)多文件上傳
ListView控件的使用
在WinForm/C#中打開一個(gè)文件
C# ListView用法詳解
delphi導(dǎo)出數(shù)據(jù)至Excel的七種方法
C# ListView控件的使用方法 簡(jiǎn)介
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服