american_iran2006
شنبه 02 مرداد 1389, 14:58 عصر
سلام:
مشکل این کد کجاست ؟
چرا وقتی میخواد مقدار تو لیست باکس بریزه برنامه کامپایل نمی شه .
کد :
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 WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Thread th;
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
th = new Thread(new ThreadStart(HI));
th.Start();
}
private void HI()
{
listBox1.Items.Add("fff");
}
}
}
علت کامپایل نشدن
Cross-thread operation not valid: Control 'listBox1' accessed from a thread other than the thread it was created on.
خیلی ضروری .
مشکل این کد کجاست ؟
چرا وقتی میخواد مقدار تو لیست باکس بریزه برنامه کامپایل نمی شه .
کد :
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 WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Thread th;
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
th = new Thread(new ThreadStart(HI));
th.Start();
}
private void HI()
{
listBox1.Items.Add("fff");
}
}
}
علت کامپایل نشدن
Cross-thread operation not valid: Control 'listBox1' accessed from a thread other than the thread it was created on.
خیلی ضروری .