学校毕业了,在外面找了一份技术支持的工作。是的,这份工作 很闲。忙的 就是就是那个点,其他的时间 都是非常的闲的。闲着无聊 ,我想学习    c#。就是感觉学的好玩!

第一天 我想说说我的学习

这是一个关于学习进程与线程的例子  灰常简单吧  就是我们经常 进程管理器  好了 废话不说了 开始讲述我的学习 这里例子的理解吧? let's  go!

首先 是那个 引用空间 一个是 using system.diagnostic  这个单词不认识 我百度了一下 说是叫诊断的意思

和  using system.collection.objectmodel   这个我也不知道 什么用法 

然后我们来定义一个结构,一个集合类,和该集合类的两个属性

public struct Fargs

{

public string pid{get;set;}

public string proname{get;set;}

}

public class allprocess:obserablecollection{}

allprocess ss=new allprocess();

allprocess ss1=new allprocess();

好了 ,准备开始了,下面是前台的代码 注意的就是那个字段的绑定 其它的 我感觉还行 

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    
        
        
            
                
                    DisplayMemberBinding="{Binding Path=pid}" />
                    DisplayMemberBinding="{Binding Path=processname}" />
                
            

        
        
        
            
                
                    DisplayMemberBinding="{Binding Path=pid}" />
                    DisplayMemberBinding="{Binding Path=processname}" />
                
            
        
        列出当前进程
        
        结束所选进程
        列出所选进程中线程
        

    

好了 往事具备 只欠东风  下面就来实现 下面的功能 

一、实现获取本计算机的所有运行的进程 注意是进程  并显示 进程的ID 和 进程的名字

 Process [] myProcess=Process.GetProcesses(".");
          ss.Clear();
          Fargs fr = new Fargs();
            foreach(Process ar in myProcess)
            {
                fr.pid = ar.Id.ToString();
                fr.processname = ar.ProcessName;
                ss.Add(fr);
            }

            listView1.ItemsSource = ss;

二、如何将所选择的的进程 进行关闭

 Fargs fr = new Fargs();
            if(listView1.SelectedItem!=null)
            {
                fr = (Fargs)listView1.SelectedItem;
                int i = Int32.Parse(fr.pid);
                try
                {
                    Process a = Process.GetProcessById(i);
                    a.Kill();

                    listView1.Items.Remove(listView1.SelectedItem);
                }
                catch
                { 

                }
            }

三、通过所选择的的进程  将该进程的所有线程显示出来

Fargs fr = new Fargs();
            if (listView1.SelectedItem != null)
            {
                fr = (Fargs)listView1.SelectedItem;
                int i = Int32.Parse(fr.pid);
                try
                {
                    Process a = Process.GetProcessById(i);
                    ProcessThreadCollection mythread = a.Threads;
                    ss1.Clear();
                    Fargs fg = new Fargs();
                    foreach (ProcessThread ar in mythread)
                    {
                        fg.pid = ar.Id.ToString();
                        fg.processname = ar.StartTime.ToString();
                        ss1.Add(fg);
                    }

                    listView2.ItemsSource = ss1;


                }
                catch
                {

                }

好了 我要的功能 基本上都实现了 其它的功能 可以加以研究 !