问题是,在我添加新类之后,当我构建解决方案时出现了错误.有什么不对?
在Form1我还没有任何代码.
刚添加新课程:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenHardwareMonitor.Hardware;
namespace OpenHardwareMonitorReport
{
class Program
{
static void Main(string[] args)
{
Computer computer = new Computer();
computer.Open();
var temps = new List<decimal>();
foreach (var hardware in computer.Hardware)
{
if (hardware.HardwareType != HardwareType.CPU)
continue;
hardware.Update();
foreach (var sensor in hardware.Sensors)
{
if (sensor.SensorType != SensorType.Temperature)
{
if (sensor.Value != null)
temps.Add((decimal)sensor.Value);
}
}
}
foreach (decimal temp in temps)
{
Console.WriteLine(temp);
}
Console.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后我在Main()上看到Program.cs和错误
using …Run Code Online (Sandbox Code Playgroud) 我有Timer3 tick事件,我将timer3间隔设置为numericupdown值:
private void timer3_Tick(object sender, EventArgs e)
{
try
{
Image iOLd = this.pictureBox1.Image;
Image img = Image.FromFile(_files[_indx].FullName);
trackBar1.Value = _indx;
label23.Text = _files[_indx].Name;
this.pictureBox1.Image = img;
if (iOLd != null)
iOLd.Dispose();
_indx++;
if (_indx >= _files.Count)
{
_indx = 0;
trackBar1.Value = 0;
}
timer3.Interval = Convert.ToInt32(numericUpDown1.Value);
}
catch
{
}
}
Run Code Online (Sandbox Code Playgroud)
我也在numericupdown valuechanged事件中做到了:
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
timer3.Interval = Convert.ToInt32(numericUpDown1.Value);
}
Run Code Online (Sandbox Code Playgroud)
问题是例如我在程序运行到10000时设置了numericupdown值并且它的移动速度非常慢然后我立即将值设置为1,所以相反,timer3间隔生效一旦我将其更改为1它等待另一个循环在10000的值中,timer3间隔作为值1.
我想要做的是当我将数字提示从10000更改为1时,它会立即改变而不是等待10000的另一轮值.
我试过这个,我希望网站的源内容将下载到一个字符串:
public partial class Form1 : Form
{
WebClient client;
string url;
string[] Search(string SearchParameter);
public Form1()
{
InitializeComponent();
url = "http://chatroll.com/rotternet";
client = new WebClient();
webBrowser1.Navigate("http://chatroll.com/rotternet");
}
private void Form1_Load(object sender, EventArgs e)
{
}
static void DownloadDataCompleted(object sender,
DownloadDataCompletedEventArgs e)
{
}
public string SearchForText(string SearchParameter)
{
client.DownloadDataCompleted += DownloadDataCompleted;
client.DownloadDataAsync(new Uri(url));
return SearchParameter;
}
Run Code Online (Sandbox Code Playgroud)
我想使用WebClient并下载数据同步,最后将网站源内容放在一个字符串中.
决定不使用任何计时器.我做的更简单.
添加了一个后台工作者.在加载了所有构造函数后,在已显示的事件中添加了一个Shown事件.在Shown事件中我启动了backgroundworker async.
在后台工作者DoWork我做:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
while(true)
{
cpuView();
gpuView();
Thread.Sleep(1000);
}
}
Run Code Online (Sandbox Code Playgroud) 例如,我有一个List:
[0] daniel
[1] moses
Run Code Online (Sandbox Code Playgroud)
现在第二个List:
[0] hello world
[1] hi everyone
Run Code Online (Sandbox Code Playgroud)
我想构建一个新的字符串列表,它将是:
[0] daniel hellow world
[1] moses hi everyone
Run Code Online (Sandbox Code Playgroud)
我该怎么做?