All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
PHP使用者注意:PHP4.3.10以下版本出现严重漏洞_[PHP教程]
SQL,Server系统视图_mssql学习_编程技术
精通数据库系列之入门-技巧篇2_mssql学习_编程技术
ASP.NET,2.0,中的母版页详解_[Asp.Net教程]
网页的新颖效果 斜着滚动的marquee_[Html教程]
C#教程:POP3与SMTP协议使用实例
初学:在PHP网站开发中如何使用cookies?_php资料_编程技术
ASP.NET2.0中GridView控件的隐藏列的问题_[Asp.Net教程]
用.NET,2.0压缩解压功能处理大型数据
ASP.NET中实现模板页_[Asp.Net教程]
Reading number is top 10 pictures
男人,就要活出棱角
A man's favorite things16
一千块钱如何创业
红楼梦金陵十二钗(2)
人美胸美腿更美2
男人帮杂志里的惹火性感美女1
初五接财神啦!五路财神齐来到
9.3阅兵全景图6-常规导弹梯队和核导弹梯队
Most cow mistress ZhaoGongXia face exposure
徐若瑄展示美丽胸围1
Download software ranking
超级战舰
Unix video tutorial9
网络管理员第三版
C++教程第四版
The Bermuda triangle3
电车之狼R
终极变速大师Speeder3.26
Unix video tutorial2
Professional killers2 data package
Ashlynn Video3
qq published in(发表于) 2014/7/11 9:28:17 Edit(编辑)
C#教程:线程的暂停与恢复

C#教程:线程的暂停与恢复

C#教程:线程的暂停与恢复

线程的暂停与恢复

线程通过调用Suspend方法来暂停线程。当线程针对自身调用Suspend 方法时,调用将会阻止,直到另一个线程继续该线程。当一个线程针对另一个线程调用.Suspend 方法时,调用是非组阻止调用,这会导致另一线程暂停。线程通过调用Resume方法来恢复被暂停的线程。无论调用了多少次Suspend方法,调用Resume方法均会使另一个线程脱离挂起状态,并导致该线程继续执行。

示例

线程的暂停与恢复

下面的代码实现了线程t的暂停与恢复。

private void Form1_Load(object sender, EventArgs e)

{

Thread t = new Thread(new ThreadStart(TestMethord));

t.Start();

t. Suspend();

MessageBox.Show("线程已暂停");

t. Resume ();

MessageBox.Show("线程已恢复");

}

public void TestMethord() //线程调用的自定义方法

{

}

完整程序代码如下:

★ ★★★★Form1.cs窗体代码文件完整程序代码★★★★★

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 _8_01

{

public partial class Form1 : Form

{

Thread t;

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

t = new Thread(new ThreadStart(TestMethord));

t.Start();

t.Suspend();

MessageBox.Show("线程已暂停");

t.Resume();

MessageBox.Show("线程已恢复");

}

public void TestMethord() //线程调用的自定义方法

{

while (true)

{

}

}

private void Form1_FormClosed(object sender, FormClosedEventArgs e)

{

t.Abort();

}

}

}

★ ★★★★Form1.designer.cs窗体设计文件完整程序代码★★★★★

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 _8_01

{

public partial class Form1 : Form

{

Thread t;

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

t = new Thread(new ThreadStart(TestMethord));

t.Start();

t.Suspend();

MessageBox.Show("线程已暂停");

t.Resume();

MessageBox.Show("线程已恢复");

}

public void TestMethord() //线程调用的自定义方法

{

while (true)

{

}

}

private void Form1_FormClosed(object sender, FormClosedEventArgs e)

{

t.Abort();

}

}

}

★ ★★★★Program.cs主程序文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.Windows.Forms;

namespace _8_01

{

static class Program

{

///



/// 应用程序的主入口点。

///


[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new Form1());

}

}

}




添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.