winform的。 private void Reminder_Load(object sender, EventArgs e)//FormLoad事件
{
Control.CheckForIllegalCrossThreadCalls = false;//是否检查跨线程调用windows控件不安全?属性为 不检查
th = new Thread(new ThreadStart(getDateTime));
th.IsBackground = false;
th.Start();
}
public void getDateTime()//获取当前时间
{
while (true)
{
lblDateTime.Text = DateTime.Now.ToString(); Thread.Sleep(50);
} }------------------------------有问题---------------------------
1、运行过后,内存一直在增加
2、谁给我讲下,abort(),join(),sleep()...等等?对于线程不太了解。请讲通俗点哦,网上的写得很繁琐。
{
Control.CheckForIllegalCrossThreadCalls = false;//是否检查跨线程调用windows控件不安全?属性为 不检查
th = new Thread(new ThreadStart(getDateTime));
th.IsBackground = false;
th.Start();
}
public void getDateTime()//获取当前时间
{
while (true)
{
lblDateTime.Text = DateTime.Now.ToString(); Thread.Sleep(50);
} }------------------------------有问题---------------------------
1、运行过后,内存一直在增加
2、谁给我讲下,abort(),join(),sleep()...等等?对于线程不太了解。请讲通俗点哦,网上的写得很繁琐。
另外你为什么不用timer呢?
拿掉看看
Thread默认是前台线程,把th.IsBackground = false;就变成后台线程了
按LZ的说法,莫非th线程一直没结束?
那用Timer timer=new Timer(……)吧!它不会新建立线程的
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void timer1_Tick(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
} }
}
timer的interval属性为:250打开任务管理器,会看到内存在每2秒8KB增加。
老师一直告诉我要慎用 timer控件各位大哥帮下忙?我只是简单的想label不断的显示系统当前时间而已,我容易吗我....