社区
C#
帖子详情
多线程问题,运行中的线程的状态为什么是WaitSleepJoin状态,迷茫中!
pq16344
2006-04-17 06:15:24
点start启动程序,但是点pause不会挂起,然后查看primeNumberThread的状态发现是WaitSleepJoin
为什么运行中的线程会是"等待睡眠连接"啊
...全文
147
2
打赏
收藏
多线程问题,运行中的线程的状态为什么是WaitSleepJoin状态,迷茫中!
点start启动程序,但是点pause不会挂起,然后查看primeNumberThread的状态发现是WaitSleepJoin 为什么运行中的线程会是"等待睡眠连接"啊
复制链接
扫一扫
分享
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
pq16344
2006-04-17
打赏
举报
回复
麻烦大家帮忙看看程序 ,刚接触多线程
pq16344
2006-04-17
打赏
举报
回复
代码如下
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using System.Text;
namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{ private System.ComponentModel.Container components = null;
private System.Windows.Forms.ListBox lstPrime;
private System.Windows.Forms.Button cmdPause;
private System.Windows.Forms.Button cmdStart;
private System.Windows.Forms.Button cmdResume;
private System.Windows.Forms.Button cmdStop;
private delegate void UpdateValue(string returnValue);
private delegate void UpdateState(string returnState);
private Thread t = null;
private Thread primeNumberThread;
public Form1()
{ InitializeComponent(); }
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.lstPrime = new System.Windows.Forms.ListBox();
this.cmdStart = new System.Windows.Forms.Button();
this.cmdPause = new System.Windows.Forms.Button();
this.cmdResume = new System.Windows.Forms.Button();
this.cmdStop = new System.Windows.Forms.Button();
this.SuspendLayout();
this.lstPrime.ColumnWidth = 100;
this.lstPrime.ItemHeight = 12;
this.lstPrime.Location = new System.Drawing.Point(64, 40);
this.lstPrime.MultiColumn = true;
this.lstPrime.Name = "lstPrime";
this.lstPrime.Size = new System.Drawing.Size(552, 376);
this.lstPrime.TabIndex = 0;
this.cmdStart.Location = new System.Drawing.Point(120, 440);
this.cmdStart.Name = "cmdStart";
this.cmdStart.TabIndex = 1;
this.cmdStart.Text = "Start";
this.cmdStart.Click += new System.EventHandler(this.cmdStart_Click);
this.cmdPause.Location = new System.Drawing.Point(232, 448);
this.cmdPause.Name = "cmdPause";
this.cmdPause.TabIndex = 2;
this.cmdPause.Text = "Pause";
this.cmdPause.Click += new System.EventHandler(this.cmdPause_Click);
this.cmdResume.Location = new System.Drawing.Point(368, 448);
this.cmdResume.Name = "cmdResume";
this.cmdResume.TabIndex = 3;
this.cmdResume.Text = "Resume";
this.cmdResume.Click += new System.EventHandler(this.cmdResume_Click);
this.cmdStop.Location = new System.Drawing.Point(480, 456);
this.cmdStop.Name = "cmdStop";
this.cmdStop.TabIndex = 4;
this.cmdStop.Text = "Stop";
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(696, 501);
this.Controls.Add(this.cmdStop);
this.Controls.Add(this.cmdResume);
this.Controls.Add(this.cmdPause);
this.Controls.Add(this.cmdStart);
this.Controls.Add(this.lstPrime);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);}
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
t = new Thread(new ThreadStart(GenerateNum));
t.Priority = System.Threading.ThreadPriority.BelowNormal;
t.Start();
}
public void GenerateNum()
{
long[] NumArray = new long[256];
for(int i = 1;i<255;i++)
{
UpdateValue pv = new UpdateValue(UpdateUI);
string[] args = new string[] {i.ToString()};
this.Invoke(pv,args);
Thread.Sleep(200);
}
}
private void cmdStart_Click(object sender, System.EventArgs e)
{
primeNumberThread = new Thread(new ThreadStart(GenerateNum));
primeNumberThread.Name = "Prime Number Example";
primeNumberThread.Priority = System.Threading.ThreadPriority.BelowNormal;
cmdPause.Enabled = true;
cmdStart.Enabled = false;
primeNumberThread.Start();
}
private void cmdPause_Click(object sender, System.EventArgs e)
{
try
{
if(primeNumberThread.ThreadState == System.Threading.ThreadState.Running)
{
primeNumberThread.Suspend();
cmdPause.Enabled = false;
cmdResume.Enabled = true;
}
}
catch(ThreadStateException ex)
{
MessageBox.Show(ex.ToString(),"Exception",MessageBoxButtons.OK,MessageBoxIcon.Error,MessageBoxDefaultButton.Button1);
}
}
private void cmdResume_Click(object sender, System.EventArgs e)
{
if(primeNumberThread.ThreadState == System.Threading.ThreadState.Suspended || primeNumberThread.ThreadState == System.Threading.ThreadState.SuspendRequested)
{
try
{
primeNumberThread.Resume();
cmdResume.Enabled = false;
cmdPause.Enabled = true;
}
catch(ThreadStateException ex)
{
MessageBox.Show(ex.ToString(),"Exception",MessageBoxButtons.OK,MessageBoxIcon.Error,MessageBoxDefaultButton.Button1);
}
}
}
private void button1_Click_1(object sender, System.EventArgs e)
{
MessageBox.Show("我日","Exception",MessageBoxButtons.OK,MessageBoxIcon.Error,MessageBoxDefaultButton.Button1);
}
public void UpdateUI(string result)
{
lstPrime.Items.Add(result);
}
}
}
BZOJ4898 & BZOJ5367 & 洛谷3778:[APIO2017]商旅——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=4898 https://www.lydsy.com/JudgeOnline/problem.php?id=5367 https://www.luogu.org/problemnew/show/P3778 在广阔的澳大利亚内陆地区长途跋涉后,你孤身一人带着一个背包来到了科巴。你被这个城市发达...
洛谷p3778[APIO2017]商旅
【洛谷p3778】【APIO2017】商旅 题面 洛谷 题解 01分数规划水题... 设总收益为\(x\)总代价为\(y\),那么题目
中
求的就是\(\frac{x}{y}<=z\)的最小取值。 把这个式子变个形:\(x-yz<=0\),然后二分\(z\)。 我们可以\(O(n^3)\)预处理出最大收益\(pro_{i,j}\)和这张图每2个点之间的最短耗时(其实就是最短路)\...
P3778 [APIO2017]商旅 Floyd+分数规划
题意: 能力有限,没有一句话题意,自己看吧 −>->−>戳这里 分析: 求盈利效率最大,要么贪心,要么分数规划,贪心不太现实,那就只能考虑分数规划了。所以我们要处理处分数规划所需要的价值和体积,由于这道题的nnn极小,只有100,完全可以floyd处理 tip:需要注意的就是,分数规划时会给ansansans乘上体积,若体积初始化为极大值会爆精度,所以体积初始化的时候手动赋值为一个较大的就可以了 代码: #include<bits/stdc++.h> using namesp
BZOJ 4898 Luogu P3778 [APIO2017]商旅 (分数规划、最短路)
题目链接: (bzoj)https://www.lydsy.com/JudgeOnline/problem.php?id=4898 (luogu)https://www.luogu.org/problemnew/show/P3778 题解: 先Floyd求任意两点最短路。 二分答案\(mid\)之后把边权乘以\(mid\)判断是否有大于\(0\)的即可。 \(O(n^2)\)枚举每一对点,然后如果...
[APIO 2017] 商旅
题目描述: qwq… 题目分析: 先预处理出两个摊点之间能够获得的最大收益,记为 val[i][j] 在获得最大收益的同时肯定是走最短路最优 弗洛伊德处理出任意两点之间的最短路 那么
问题
就变成了求图上的一个最大比率环 即 求max(∑val∑cost)max(∑val∑cost)max(\frac{\sum val}{\sum cost}) 01分数规划+SPFA判断正环即可 ...
C#
111,128
社区成员
642,533
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章