I am trying to make a timer that refreshes every 5 seconds. Here is my code:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;
using System.Timers;
namespace rpanel_server
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
Timer MyTimer = new Timer();
MyTimer.Interval = (4000);
MyTimer.Tick += new EventHandler(MyTimer_Tick);
MyTimer.Start();
}
private PerformanceCounter theMemCounter = new PerformanceCounter("Memory", "Available MBytes");
// Main stuff
public object getCPUCounter()
{
PerformanceCounter cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
// will always start at 0
dynamic firstValue = cpuCounter.NextValue();
System.Threading.Thread.Sleep(1000);
// now matches task manager reading
dynamic secondValue = cpuCounter.NextValue();
return secondValue;
}
void MainFormLoad(object sender, EventArgs e)
{
label8.Text = getCPUCounter() + "%";
label9.Text = theMemCounter.NextValue().ToString();
}
private void MyTimer_Tick(object sender, EventArgs e)
{
label8.Text = getCPUCounter() + "%";
label9.Text = theMemCounter.NextValue().ToString();
}
}
}
When I run that code, I get this:'Timer' is an ambiguous reference between 'System.Windows.Forms.Timer' and 'System.Timers.Timer' (CS0104)
No matter what timer I make, it will still throw that error. I don't know what is wrong with this code.