陈宝刚---享受生活,追逐梦想!
理想是心中的火焰,有追求的人才是幸福的人!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Configuration;
using System.Xml;

namespace WindowsFormsApplication1
{
    public partial class JCCLOS : Form
    {
        public JCCLOS()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void JCCLOS_Load(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcesses();
            foreach (System.Diagnostics.Process myProcess in myProcesses)
            {
                if (myProcess.MainWindowTitle.Length > 0)
                    listBox1.Items.Add(myProcess.ProcessName.ToString().Trim());
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

一点小技巧:

System.Diagnostics.Process.GetProcesses();

Process.GetProcesses();

看出有什么区别吗???

很多人说一样吗?我说不一样,前一个是绝对引用,后一个是相对引用。可能是VS的一个BUG,因为后都好使,前者确引用不到GetProcesses();这个方法,提示信息为:错误 1 “WindowsFormsApplication1.Process”并不包含“GetProcesses”的定义 ,十分之奇怪呀!请大家引以为鉴!!切记空间命名引用,有的时候要绝对引用,否则有的时候可以找到空间中的对应方法!


 

posted on 2009-01-07 21:14  追梦人RUBY  阅读(496)  评论(0编辑  收藏  举报