我是新來的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