使用Pcap.Net和线程抛出'System.NullReferenceException'

时间:2015-10-03 08:47:37

标签: c# nullreferenceexception pcap.net

我有这个方法:

 protected void AddNewCustomer(object sender, EventArgs e)
{

    Control control = null;
    if (GridView1.FooterRow != null)
    {
        control = GridView1.FooterRow;
    }
    else
    {
        control = GridView1.Controls[0].Controls[0];
    }
    string SlNo = (control.FindControl("txtSlNo") as TextBox).Text;
    string Code = (control.FindControl("txtcode") as TextBox).Text;
    string details = (control.FindControl("txtdetails") as TextBox).Text;
    using (SqlConnection con = new SqlConnection(""))
    {
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.Connection = con;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "INSERT INTO [Qtattemp] VALUES(@Code,@details,@SlNo)";
            cmd.Parameters.AddWithValue("@SlNo", SlNo);
            cmd.Parameters.AddWithValue("@Code", Code);  
            cmd.Parameters.AddWithValue("@details", details);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }
    }
    Response.Redirect(Request.Url.AbsoluteUri);
}

当我启动程序时,通过

调用此方法
public void rc()
{
    try{
        using (PacketCommunicator communicator = device1.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
        {
            richTextBox1.AppendText("Listening on " + device1.Description + "... \r\n");

            // start the capture
            communicator.ReceivePackets(0, PacketHandler);
            communicator.Break();
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

它在“使用(PacketCommunicator ....”

的行尾)抛出了这个
  

在......

中发生了'System.NullReferenceException'类型的未处理异常      

附加信息:未将对象引用设置为对象的实例。

添加信息:当我没有方法“rc”和线程,并且代码在构造函数中时,我没有遇到此问题。

0 个答案:

没有答案