我是新来的C#和多线程。我有这个代码来开始使用多线程,但时钟滴答没有开始。这段代码有什么问题?没有错误发生,因为我猜想它是一个逻辑错误。任何帮助,将不胜感激。线程未启动
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.Threading;
namespace Implementing_Databases
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
picturebox1.Location=new Point(0,20);
pictureBox2.Location = new Point(0, 60);
}
int B1 = 0;
int B2 = 0;
private void Form1_Load(object sender, EventArgs e)
{
Thread Th1 = new Thread(Go1);
Thread Th2 = new Thread(Go2);
Th1.Start();
Th2.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
picturebox1.Left = B1;
B1 += 5;
}
private void timer2_Tick(object sender, EventArgs e)
{
pictureBox2.Left = B2;
B2 += 5;
}
void Go1()
{
timer1.Start();
}
void Go2()
{
timer2.Start();
}
}
}
我没有看到任何定时器声明? –
我使用了工具箱中的计时器。我猜这是背景声明? – wish568
为什么不从'Form1_Load'方法调用'timer1.Start()'。在'Thread'中包装它在这种情况下不会存档。 – Dzienny