以下是截图:
源码:
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
private delegate void d(int a, int b);
d dt;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int a = int.Parse(textBox1.Text);
int b =int.Parse(textBox2.Text);
Thread t = new Thread(()=>ThreadTest(a,b));
t.Start();
textBox1.Text = "a";
}
private void Result(int a,int b)
{
label1.Visible = true;
label1.Text = Convert.ToString(a, b);
}
private void ThreadTest(int a,int b)
{
if (label1.InvokeRequired)
{
while (!label1.IsHandleCreated)
{
if (label1.Disposing || label1.IsDisposed)
return;
}
dt = new d(Result);
label1.Invoke(dt, new object[] { a, b });
}
else label1.Text = Convert.ToString(a + b);
}
}
}
运行的时候
按了button后:
一直这样,有时还会在int a=Convert.ToInt32(textBox1.Text)报字符串转换为datetime应先分析什么什么的,我这里根本就没转为字符串格式。
求大神指点指点