在開辟了多個線程后,
突然需要使用Thread.Sleep()來阻塞5s某一線程,
這下迷糊了,使用Thread.Sleep()的結果到底影響那個線程呢?
請賜教!
突然需要使用Thread.Sleep()來阻塞5s某一線程,
這下迷糊了,使用Thread.Sleep()的結果到底影響那個線程呢?
請賜教!
解决方案 »
- 请问下CharacterSet是ISO-8859-1的网页怎么读?
- 急!!未能找到文件"bin\Debug\**.exe.config"
- 二个正则求解...
- 求vs2005的扩展包,我想用linq啊
- TreeView文字换行
- 加载的DLL控件,如何激活事件?
- 刚学C#,有几个入门问题望各位指点,散分100
- 如何获取一个 第三方窗口 中的相关控件信息?
- 高手!!!!!!!!!!!!!!!!!!!!ajaxpro 返回DATASET后JS怎么删除DATASET中的行..
- 如何让一个程序运行完毕的时候删除自己?
- 怎样获取IE的url
- InvalidArgument=“0”的值对于“index”无效。 参数名: index
前缀是 System.Thread.
//不知所以不明
Thread.Sleep();
//Namespace References
using System.Threading;/// <summary>
/// method for retrieving the name of the current thread
/// </summary>
/// <returns></returns>
public string RetrieveCurrentThreadName()
{
//variable to hold the thread name
string name;
try
{
//get the current thread
Thread current = Thread.CurrentThread;
name = current.Name;
}
catch (ThreadStateException ex)
{
name = string.Empty;
MessageBox.Show(ex.Message);
}
catch (Exception ex)
{
name = string.Empty;
MessageBox.Show(ex.Message);
}
return name;
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace TEST
{
public delegate void _Delegate_T(); public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} _Delegate_T _DT_T1 = null;
_Delegate_T _DT_T2 = null;
_Delegate_T _DT_T3 = null;
Thread T1 = null;
Thread T2 = null;
Thread T3 = null; private void button1_Click(object sender, EventArgs e)
{
T1 = new Thread(p1);
T2 = new Thread(p2);
T3 = new Thread(p3); _DT_T1 = new _Delegate_T(_DT_T_M1);
_DT_T2= new _Delegate_T(_DT_T_M2);
_DT_T3 = new _Delegate_T(_DT_T_M3); T1.IsBackground = true;
T1.Start(); T2.IsBackground = true;
T2.Start(); T3.IsBackground = true;
T3.Start();
} public void _DT_T_M1()
{
if (progressBar1.InvokeRequired)
{
progressBar1.Invoke(_DT_T1);
}
else
{
progressBar1.Increment(1);
if (progressBar1.Value == progressBar1.Maximum)
progressBar1.Value = 0;
}
}
public void _DT_T_M2()
{
if (progressBar2.InvokeRequired)
{
progressBar2.Invoke(_DT_T2);
}
else
{
progressBar2.Increment(1);
if (progressBar2.Value == progressBar2.Maximum)
progressBar2.Value = 0;
}
}
public void _DT_T_M3()
{
if (progressBar3.InvokeRequired)
{
progressBar3.Invoke(_DT_T3);
}
else
{
progressBar3.Increment(1);
if (progressBar3.Value == progressBar3.Maximum)
progressBar3.Value = 0;
}
} public void p1()
{
while (this.T1.IsAlive)
{
Thread.Sleep(500);
_DT_T1();
}
}
public void p2()
{
while (this.T2.IsAlive)
{
Thread.Sleep(1000);
_DT_T2();
}
}
public void p3()
{
while (this.T3.IsAlive)
{
Thread.Sleep(2000);
_DT_T3();
}
}
}
}