用线程时,界面假死问题
我主要想实现的是:我新建了form1,form2,点击form1的按钮出现form2,然后form2.show的同时,运行一些耗时的函数。问题:容易造成form1的假死,所以我想用线程运行耗时函数时,form1不受影响,不出现钝机现象,用createthread函数创建线程时,为什么会对inttostr函数有出错现象?线程类TThread我试过了,没有达到我的要求,还是会出现假死现象,Synchronize也用了
没效果。 --------------------编程问答-------------------- 线程例子:
using System;--------------------编程问答-------------------- 这个C#不太会,能翻译成delphi的么? --------------------编程问答--------------------
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private delegate void MoveLabel(int val);//声明代理
Thread td;
private void Form1_Load(object sender, EventArgs e)
{
td = new Thread(new ThreadStart(ThreadFun));
td.Start();
}
void SetOffset(int val)
{
label1.Text = "从子线程里传入的值是:" + val.ToString();
}
private void ThreadFun()
{
if (this.InvokeRequired)
{
MoveLabel d = new MoveLabel(SetOffset);
object[] arg = new object[] { 1 };//要传入的参数值
this.Invoke(d, arg);
}
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yfqvip/archive/2009/12/17/5025052.aspx
友情帮顶下!顺便学习学习!
补充:.NET技术 , 其他语言