using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace testThreads
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void countToLots()
{
for (int i = 0; i < 10000000; i++)
{
textBox1.Text = "Counting to 10000000, value is " + i + Environment.NewLine;
}
}
public void countToZero()
{
for (int i = 10000000; i > 0; i--)
{
textBox2.Text = "Counting to 0, value is " + i + Environment.NewLine;
}
}
private void button1_Click(object sender, EventArgs e)
{
Thread countUp = new Thread(new ThreadStart(countToLots));
Thread countDown = new Thread(new ThreadStart(countToZero));
countUp.Start();
countDown.Start();
}
private void button2_Click(object sender, EventArgs e)
{
textBox3.Text = "Bobby bob bob " + Environment.NewLine;
}
}
}
私は本当にこれを掛けなければなりません - 私はエラーメッセージが表示される理由を理解できません。誰かが私を助けてくれますか?スレッディングの基礎
クロススレッド操作有効ではありません:それは に作成されたスレッド以外のスレッドからアクセス コントロール「textBox1テキストボックス」。
私はまだ同じ方法でメソッドを呼び出しますか? – tom
@tom yes; *コントロールに触れるのは痛みだけです。もちろん、それは単純化されています。 **複数のスレッドを持っている場合、**共有データ**にはたくさんの考えが必要です –
この種の良い本をお勧めしますか?私は大学でそれをオプションとして勉強する機会を得ましたが、occam piは本当に私を – tom