日期:2014-05-17  浏览次数:20714 次

为什么这段代码会失去响应,我是C#菜鸟
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);

  }

  }


------解决方案--------------------
1看看button1 绑定的事件是不是 button1_Click
2打断点瞧瞧问题在哪里
------解决方案--------------------
没反应是单击 button1的时候不进入到 button1_Click 还是怎么的??
假如是 不进入到 button1_Click 那么你到当前from的 Designer.cs 文件中去检查下:
this.button1.Click += new System.EventHandler(this.button1_Click);看是不是是这样绑定的....
------解决方案--------------------
那这个自己打个断点跟咯,,看在哪死掉 了.
------解决方案--------------------
faka = true;

while (faka)
这个 是不是你搞错了???while会无线循环的 ...你在while中又没有 修改faka;;;