こんばんは、私は今、PCの起動してからの時間を取得したいと思って、
以下のコードを書いたのですが、いい感じに動作してくれません。時間にズレが出ます。
C#
1public partial class Form1 : Form 2 { 3 PerformanceCounter perfCPUconter = new PerformanceCounter("Processor Information", "% Processor Time", "_Total"); 4 PerformanceCounter perfMemconter = new PerformanceCounter("Memory", "Available MBytes"); 5 PerformanceCounter perfSystemconter = new PerformanceCounter("System", "System Up Time"); 6 public Form1() 7 { 8 InitializeComponent(); 9 } 10 11 private void timer1_Tick(object sender, EventArgs e) 12 { 13 label1.Text = "CPU使用率" + " " + (int)perfCPUconter.NextValue() + " " + "%"; 14 label2.Text = "利用可能メモリ量" + " " + (int)perfMemconter.NextValue() + " " + "MB"; 15 label3.Text = "PC起動時間" + " " + (int)perfSystemconter.NextValue() / 600 / 600 + "日" + (int)perfSystemconter.NextValue() / 60 / 60 + "時間" + (int)perfSystemconter.NextValue() / 6 / 6 + "分"; 16 } 17 }
このように書くと時間にずれが生じます。
一番簡単な書き方で高精度のものを書きたいのですがわからないため質問させていただきました。
ご回答よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。