为什么这段代码会失去响应,我是C#菜鸟

CCC的 2012-09-07 05:01:08
private void button1_Click(object sender, EventArgs e)

{

string EPCNo;

int i = 0;

if (this.Text == "发卡程序--未找到发卡器")

{

readers = reader.GetReaderList();

if (readers.Count == 0)

{

MessageBox.Show("未找到发卡器,请先插好发卡器");

return;

}

else

{

reader.Connect(readers[0]);

this.Text = "发卡程序--发卡器已连接";

}

}

button1.Enabled = false;

button2.Enabled = true;

button3.Enabled = false;

faka = true;

while (faka)

{

if (i == Convert.ToInt16(textBox1.Text))

{

listView1.Items.RemoveAt(0);

i = 0;

}

ReadEpcResult readresult = reader.ReadEpc();

if (readresult.ReadResult.Result == AccessResult.Success)

{

EPCNo = readresult.TagAccessed.Epc;



if (EPCNo != listView1.Items[0].Text)

{

ProgramEpcParams pep = new ProgramEpcParams();

pep.NewEpc = listView1.Items[0].Text;

pep.AntennaPortNumber = 0;

pep.AccessPassword = "00000000";



ProgramEpcResult writeresult = reader.ProgramEpc(pep);

if (writeresult.WriteResult.Result == AccessResult.Success)

{

i = i + 1;

richTextBox1.Text = listView1.Items[0].Text + "发卡成功" + "\n";

}

}

else

{

richTextBox1.Text = listView1.Items[0].Text + "已发放,请放下一张" + "\n";

}

}

Thread.Sleep(100);

}

}
...全文
117 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhanglong19891129 2012-09-07
  • 打赏
  • 举报
回复
Application.DoEvents 这个东西 是不是停止当前处理..等待其他消息啊?这个我还没用过
CCC的 2012-09-07
  • 打赏
  • 举报
回复
草了个蛋蛋,加上Application.DoEvents就行了
CCC的 2012-09-07
  • 打赏
  • 举报
回复
停止事件有里有修改faka为false
CCC的 2012-09-07
  • 打赏
  • 举报
回复
可以不停的读卡并且将卡号放到richtextbox ,只是我想让它停止,一点停止按钮,不响应停止按钮的事件
zhanglong19891129 2012-09-07
  • 打赏
  • 举报
回复
faka = true;

while (faka)
这个 是不是你搞错了???while会无线循环的 ...你在while中又没有 修改faka;;;
zhanglong19891129 2012-09-07
  • 打赏
  • 举报
回复
那这个自己打个断点跟咯,,看在哪死掉 了.
CCC的 2012-09-07
  • 打赏
  • 举报
回复
会执行button1_Click ,是程序死掉了一样
zhanglong19891129 2012-09-07
  • 打赏
  • 举报
回复
没反应是单击 button1的时候不进入到 button1_Click 还是怎么的??
假如是 不进入到 button1_Click 那么你到当前from的 Designer.cs 文件中去检查下:
this.button1.Click += new System.EventHandler(this.button1_Click);看是不是是这样绑定的....
二当家 2012-09-07
  • 打赏
  • 举报
回复
1看看button1 绑定的事件是不是 button1_Click
2打断点瞧瞧问题在哪里
CCC的 2012-09-07
  • 打赏
  • 举报
回复
private void button1_Click(object sender, EventArgs e)

{

string EPCNo;

int i = 0;

if (this.Text == "发卡程序--未找到发卡器")

{

readers = reader.GetReaderList();

if (readers.Count == 0)

{

MessageBox.Show("未找到发卡器,请先插好发卡器");

return;

}

else

{

reader.Connect(readers[0]);

this.Text = "发卡程序--发卡器已连接";

}

}

button1.Enabled = false;

button2.Enabled = true;

button3.Enabled = false;

faka = true;

while (faka)

{

if (i == Convert.ToInt16(textBox1.Text))

{

listView1.Items.RemoveAt(0);

i = 0;

}

ReadEpcResult readresult = reader.ReadEpc();

if (readresult.ReadResult.Result == AccessResult.Success)

{

EPCNo = readresult.TagAccessed.Epc;



if (EPCNo != listView1.Items[0].Text)

{

ProgramEpcParams pep = new ProgramEpcParams();

pep.NewEpc = listView1.Items[0].Text;

pep.AntennaPortNumber = 0;

pep.AccessPassword = "00000000";



ProgramEpcResult writeresult = reader.ProgramEpc(pep);

if (writeresult.WriteResult.Result == AccessResult.Success)

{

i = i + 1;

richTextBox1.Text = listView1.Items[0].Text + "发卡成功" + "\n";

}

}

else

{

richTextBox1.Text = listView1.Items[0].Text + "已发放,请放下一张" + "\n";

}

}

Thread.Sleep(100);

}

}
zhanglong19891129 2012-09-07
  • 打赏
  • 举报
回复
你把你的 代码 用C#格式包下吧,这个号难看

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧