代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
挂起恢复运行线程代码
作者:
xqf222
/ 发布于
2014/2/25
/
388
//C# 挂起恢复运行线程代码 暂时没找到和测试出替换Thread.Resume()恢复运行和Thread.Suspend()暂停挂起的函数 //添加引用 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using System.Threading; using System.Collections; //定义变量 private Thread convertThread; private Mutex mutex = new Mutex(); Queue myThreadQueue=new Queue(); //按钮事件 private void btnConstraintToBig5_Click(object sender, EventArgs e) { this.btnConstraintToBig5.Enabled = false; //测试数据库连接 this.richTextBox1.Text = ""; CurrentServerName = this.txtServerName.Text.Trim(); CurrentDatabaseName = this.txt_DatabaseName.Text.Trim(); CurrentUserName = this.txt_UserName.Text.Trim(); CurrentUserPassword = this.txt_Password.Text.Trim(); CurrentConnectionString = "Data Source=" + CurrentServerName + ";Initial Catalog=Master;User ID=" + CurrentUserName + ";password=" + CurrentUserPassword; DataTable myDataTable = new DataTable(); try { SqlConnection thisConnection = new SqlConnection(CurrentConnectionString); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = new SqlCommand("select * from sysservers", thisConnection); DataSet ds = new DataSet(); da.Fill(ds, "Temp"); myDataTable = ds.Tables["Temp"]; thisConnection.Close(); if (myDataTable.Rows.Count > 0) { this.richTextBox1.Text += "/r/n建立到数据库连接成功"; CurrentConnectionString = "Data Source=" + CurrentServerName + ";Initial Catalog=" + CurrentDatabaseName + ";User ID=" + CurrentUserName + ";password=" + CurrentUserPassword; convertThread = new Thread(new ThreadStart(StartConvertConstraintToBig5)); convertThread.IsBackground = true; convertThread.Start(); } else { this.richTextBox1.Text += "/r/n建立到数据库连接失败"; } } catch (Exception ex) { this.richTextBox1.Text += "/r/n建立到数据库连接出错" + ex.Message; } } //线程调用函数 /// <summary> /// 线程调用的监听转换数据表约束到简体版函数 /// </summary> private void StartConvertConstraintToBig5() { lock (myThreadQueue) { mutex.WaitOne(); myDataBaseConverter.BeginConvertingMessage += new DataBaseEventHandler(OnBeginMessageReceived); myDataBaseConverter.EndConvertingMessage += new DataBaseEventHandler(OnEndMessageReceived); myDataBaseConverter.CurrentConvertingMessage += new DataBaseEventHandler(OnCurrentMessageReceived); myDataBaseConverter.ConvertingErrorMessage += new DataBaseEventHandler(OnErrorMessageReceived); myDataBaseConverter.ConvertTableConstraintToBig5(CurrentConnectionString); mutex.ReleaseMutex(); } } //暂停恢复线程运行 private void btnPauseConverting_Click(object sender, EventArgs e) { if (convertThread != null) { Console.WriteLine("当前线程状态名称:" + convertThread.ThreadState.ToString()); Console.WriteLine("当前线程状态编号:" + Convert.ToInt32(convertThread.ThreadState).ToString()); if (this.btnPauseConverting.Text == "继续转换" && Convert.ToInt32(convertThread.ThreadState) == 68) { try { this.btnPauseConverting.Text = "暂停转换"; convertThread.Resume(); } catch (Exception msg) { MessageBox.Show(msg.ToString(), "异常"); } } else if (this.btnPauseConverting.Text == "暂停转换" && Convert.ToInt32(convertThread.ThreadState) == 36) { try { this.btnPauseConverting.Text = "继续转换"; convertThread.Suspend(); } catch (Exception msg) { MessageBox.Show(msg.ToString(), "异常"); } } } }
试试其它关键字
挂起恢复运行线程
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
xqf222
贡献的其它代码
(
82
)
.
VB编写的登录局域网内的sql2000数据库服务器
.
ASP .NET登录界面用户验证码
.
VB操作ACCESS数据库
.
批量发送邮件程序
.
批量抓取网页代码中的HTTP和邮件地址
.
禁止站外提交参数测试
.
FTP网站文件到本地的
.
调用对应的应用程打开文件
.
抓取邮件内容解析
.
保存文件时候的弹出选择要保存的文件夹带新建文件夹效
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3