using System.Diagnostics;

using System.Diagnostics;

 

using System.Diagnostics 命名空间 包含了能够与系统进程 事件日志 和性能计数器进行交互的类 一般用于帮助诊断和调试应用程序 例如 Debug类用于帮组调试代码 Process类能够控制进程访问 Trace类能够跟踪代码的执行情况

Process 用于操作本地或者远程进程打访问 通过Process 可以在托管环境下很容易的操作对外部进程的启动或者停止 

代码
复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace TestEqual
{
    
class Program
    {
        
static void Main(string[] args)
        {    
            Process myProcess 
= new Process();
            myProcess.StartInfo.FileName 
= "iexplore.exe";
            myProcess.StartInfo.Arguments 
= "http://www.baidu.com";
            myProcess.Start();
        }

       
    }
    
}
复制代码

必须设置相应的FileName和Arguments属性

 

Stopwatch 用于高精度检测运行时间  Start方法表示开始测量  Stop表示停止测量 Reset 表示停止测量并重置 为0最后以Elapsed返回测量时间

代码
复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Diagnostics;
namespace TestEqual
{
    
class Program
    {
        
static void Main(string[] args)
        {
            ArrayList mylist 
= new ArrayList();
            Stopwatch watch 
= Stopwatch.StartNew();
            
for (int i = 0; i < 100000; i++)
            {
                mylist.Add(i);
            }
            watch.Stop();
            Console.WriteLine(watch.ElapsedMilliseconds);
            Console.ReadLine();
        }


    }
}
复制代码

 

EventLog  提供了写入 读取 创建 和删除事件日志的方法

代码
复制代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; using System.Diagnostics; namespace TestEqual {     class Program     {         static void Main(string[] args)         {
            EventLog mylog 
= new EventLog("MyLog"".""AnyLog");             mylog.WriteEntry("It is my log.", EventLogEntryType.Information, 1);             foreach (EventLogEntry ele in mylog.Entries)             {                 Console.WriteLine(ele.Message);             }         }
    } }
posted @ 2012-08-04 00:20  小薇林  阅读(176)  评论(0编辑  收藏  举报