2017-07-02 111 views
1

我想做一個電腦診斷工具我這樣做在命令提示符下,我想這樣做在Windows窗體中我使用的IDE是Visual Studio 2015對不起,如果問題是明顯的或無關的我在C#我環顧四周,新的,但找不到任何有用的東西來處理這個錯誤 -Thanks馬哈茂德C#Visual Studio Windows窗體錯誤CS1501

這裏是工作的命令提示符代碼:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Diagnostics; 
using System.Threading; 

namespace mahmoodspcdiagnostictool_m.p.d.t_ 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      Console.WriteLine("To begin diagnostic type start diagnostic"); 
      string startdiagnostic = Console.ReadLine(); 
      if (startdiagnostic == "start diagnostic") 
      { 
       PerformanceCounter perfCpuCount = new PerformanceCounter("Processor Information", "% Processor Time", "_Total"); 

       PerformanceCounter perfMemCount = new PerformanceCounter("Memory", "Available MBytes"); 

       Console.WriteLine("Cpu Usage: Avalible RAM:"); 
       while (true) 
       { 
        Thread.Sleep(2500); 
        Console.Write("{0}%", perfCpuCount.NextValue()); 
        Console.WriteLine("  {0} MB", perfMemCount.NextValue()); 
       } 
      } 

     } 
    } 
} 

這裏是不工作Windows窗體代碼:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using System.Diagnostics; 
using System.Threading; 

namespace MahmoodsPCDiagnosticTool_M.P.D.T__GUI_Edition_ 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     PerformanceCounter perfCpuCount = new PerformanceCounter("Processor Information", "% Processor Time", "_Total"); 

     PerformanceCounter perfMemCount = new PerformanceCounter("Memory", "Available MBytes"); 

     //When the start button is clicked this code is to be executed 
     private void button1_Click(object sender, EventArgs e) 
     { 
      richTextBox4.AppendText("{0}%\r\n", perfCpuCount.NextValue()); 
      richTextBox5.AppendText("{0} MB\r\n", perfMemCount.NextValue()); 
     } 

     private void Form1_Enter(object sender, EventArgs e) 
     { 

     } 

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

     private void aboutToolStripMenuItem_Click(object sender, EventArgs e) 
     { 
      MessageBox.Show("This is a pc diagnostic tool it was made by Mahmood Badr."); 
     } 

     private void richTextBox2_TextChanged(object sender, EventArgs e) 
     { 

     } 

     private void richTextBox4_TextChanged(object sender, EventArgs e) 
     { 

     } 
    } 
} 
+0

請界定「不工作」 –

+0

它不是在某種意義上說,它給了我我很高興有人來解決它的錯誤 – Mahmood

+0

工作。但下次請包括您收到的任何錯誤,以便我們能夠更好地爲您提供幫助。 「這不起作用」沒有告訴我們很多,也沒有提供錯誤細節的「它給了我一個錯誤」。 –

回答

0

您的示例顯示您使用richTextBox,它沒有AppendText(string, string)方法,只有AppendText(string)方法。

這工作:

PerformanceCounter perfCpuCount = new PerformanceCounter("Processor Information", "% Processor Time", "_Total"); 

PerformanceCounter perfMemCount = new PerformanceCounter("Memory", "Available MBytes"); 

//When the start button is clicked this code is to be executed 
private void button1_Click(object sender, EventArgs e) 
{ 
    richTextBox4.AppendText($"{perfCpuCount.NextValue()}%{Environment.NewLine}"); 
    richTextBox5.AppendText($"{perfMemCount.NextValue()} MB{Environment.NewLine}"); 
} 

*與C#7.0

+1

如果有人想知道這段代碼是否有效 – Mahmood

相關問題