程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 做COM+時用到的一些方法

做COM+時用到的一些方法

編輯:C#入門知識

//獲取CPU的序列號
        private string GetCpuID()
        {
            try
            {
                //獲取CPU序列號代碼
                string cpuInfo = "";//cpu序列號
                ManagementClass mc = new ManagementClass("Win32_Processor");
                ManagementObjectCollection moc = mc.GetInstances();
                foreach (ManagementObject mo in moc)
                {
                    cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
                }
                moc = null;
                mc = null;
                return cpuInfo;
            }
            catch
            {
                return "unknow";
            }
            finally
            {
            }
        }
//檢索所有正在運行的COM+組件,和它們的應用程序ID
public void GetCOMPlusApplicationsList()
  {
   COMSVCSLib.MtsGrp GrpObj = null;
   Type dcomType = Type.GetTypeFromProgID("mts.MtsGrp");
   Object dcomObj = Activator.CreateInstance( dcomType );
   GrpObj = (COMSVCSLib.MtsGrp) dcomObj;
   object obj = null;
   COMSVCSLib.COMEvents eventObj = null;
   
   for (int i = 0 ;i < GrpObj.Count ; ++i)
   {
    GrpObj.Item (i, out obj);
    eventObj = (COMSVCSLib.COMEvents) obj;
    
    AddtoListView(eventObj.GetProcessID(),eventObj.PackageName);
    Marshal.ReleaseComObject(obj);
    obj = null;
    Marshal.ReleaseComObject(eventObj);
    eventObj = null;
   }
   Marshal.ReleaseComObject( dcomObj );
   dcomObj = null;
   return;
  }


/**/
        /// <summary>
        /// 性能計數器,用於獲取CPU空閒百分比
        /// </summary>
        private static PerformanceCounter mIdle = new PerformanceCounter("Processor", "% Processor Time", "Idle");
        private Label label1;
        /**/
        /// <summary>
        /// 性能計數器,用於獲取CPU總利用率
        /// </summary>
        private static PerformanceCounter mTotal = new PerformanceCounter("Processor", "% Processor Time", "_Total");
 string  nVal = mTotal.NextValue().ToString();
 //PerformanceCounter cpuCounter;
            //PerformanceCounter ramCounter;

            //cpuCounter = new PerformanceCounter();

            //cpuCounter.CategoryName = "Processor";
            //cpuCounter.CounterName = "% Processor Time";
            //cpuCounter.InstanceName = "_Total";
            //ramCounter = new PerformanceCounter("Memory", "Available MBytes");


//當前程序的路徑
System.AppDomain.CurrentDomain.BaseDirectory.ToString();


//保存文件

SaveFileDialog sf = new SaveFileDialog();
            //設置文件保存類型
            sf.Filter = "txt文件|*.txt|所有文件|*.*";
            //如果用戶沒有輸入擴展名,自動追加後綴
            sf.AddExtension = true;
            //設置標題
            sf.Title = "寫文件";
            //如果用戶點擊了保存按鈕
            if (sf.ShowDialog() == DialogResult.OK)
            {
                this.txtFilePath.Text = sf.FileName;
            }
System.IO.StreamWriter f2 = new System.IO.StreamWriter(path, true, System.Text.Encoding.UTF8);
                f2.WriteLine(txtStrings);

    

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved