基本信息
源码名称:wpf任务管理器源码
源码大小:0.20M
文件格式:.rar
开发语言:C#
更新时间:2020-06-06
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍
完成类似任务管理器界面

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp2
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            M1();
        }
        List<Data> list = new List<Data>();
        private void b1_Click(object sender, RoutedEventArgs e)
        {
            string k = t3.Text;
            Process p = new Process();
            p.StartInfo.FileName = k;
            try
            {
                p.Start();
            }
            catch (Exception)
            {

                MessageBox.Show("启动失败");
            }
        }

        private void b2_Click(object sender, RoutedEventArgs e)
        {
            var a = t1.SelectedItem;
            Data da = a as Data;
            Process p = Process.GetProcessById(da.Id);
            try
            {
                p.Kill();
            }
            catch (Exception)
            {

                MessageBox.Show("error");
            }
            M1();
        }
        private void M1() {
            t1.ItemsSource = null;
            list.Clear();
            Process[] p = Process.GetProcesses();
            tt.Text= "进程数:" p.Length.ToString();
            foreach (Process item in p)
            {
                Data data = new Data();
                data.Id = item.Id;
                try
                {
                    data.Name = item.ProcessName;
                }
                catch (Exception)
                {
                    data.Name = "";
                }
                data.Memory=item.WorkingSet64.ToString();
                try
                {
                    data.dateTime =item.StartTime.ToString();
                }
                catch (Exception)
                {

                    data.dateTime = "";
                }
                try
                {
                    data.Filename=item.MainModule.FileName;
                }
                catch (Exception)
                {

                    data.Filename = "";
                }
                list.Add(data);
            }
            t1.ItemsSource = list;
        }
        public class Data {
            public int Id { get; set; }
            public String Name { get; set; }
            public String Memory { get; set; }
            public String dateTime { get; set; }
            public String Filename { get; set; }
        }

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {

        }
    }
}