一、问题来源
跨线程操作时会报错:System.InvalidOperationException:“线程间操作无效: 从不是创建控件的线程访问它。
二、问题代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
//using MSExcel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.IO;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
List<string> savedData;
public string stra = null;
public string strs = null;
public string stra1 = null;
public string stra2 = null;
String[] recevedData;
string path;
public string filename;
Thread th;
Thread thWriteExcel;
Socket socketSend;
bool isCollecting = false;
string