小编use*_*479的帖子

在我的项目中添加了一个新类并得到错误说Program.Main()有多个条目为什么?

问题是,在我添加新类之后,当我构建解决方案时出现了错误.有什么不对?

在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)

c#

15
推荐指数
7
解决办法
4万
查看次数

如何根据numericupdown值实时更改定时器间隔?

我有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的另一轮值.

c#

6
推荐指数
2
解决办法
2万
查看次数

如何将网站内容下载到字符串?

我试过这个,我希望网站的源内容将下载到一个字符串:

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并下载数据同步,最后将网站源内容放在一个字符串中.

c#

3
推荐指数
3
解决办法
1万
查看次数

如何使用带有计时器滴答的BackgroundWorker?

决定不使用任何计时器.我做的更简单.

添加了一个后台工作者.在加载了所有构造函数后,在已显示的事件中添加了一个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)

c# multithreading timer

1
推荐指数
1
解决办法
2万
查看次数

我有两个字符串列表如何从每个List索引创建一个字符串与另一个?

例如,我有一个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)

我该怎么做?

c#

1
推荐指数
1
解决办法
76
查看次数

标签 统计

c# ×5

multithreading ×1

timer ×1