线程间操作无效: 从不是创建控件“listBox1”的线程访问它
我用VS2005做个网络聊天程序,使用了多线程技术,但会出现这个异常,求高手们如何解决这个异常...原代码如下!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace ChatServer
{
public partial class Form1 : Form
{
private IPAddress myIP = IPAddress.Parse( "127.0.0.1 ");
private IPEndPoint myserver;
private Socket sockets;
private Socket acsocket;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
myIP = IPAddress.Parse(textBox1.Text);
}
catch
{
MessageBox.Show( "你输入的IP地址格式不正确! ");
}
try
{
Thread thread = new Thread(new ThreadStart(accp));
thread.Start();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);