当我们使用线程已被中止 [英] Thread was being aborted when we use

查看:109
本文介绍了当我们使用线程已被中止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

System.Threading.ThreadAbortException:线程已被中止结果。
  在System.Threading.Thread.AbortInternal()在
  System.Threading.Thread.Abort在(对象将stateInfo)
  System.Web.Htt presponse.End()在
  System.Web.Htt presponse.Redirect(字符串URL,布尔endResponse)结果
  在System.Web.Htt presponse.Redirect(字符串URL)的
  taxi_selection.lnkbtnconfirm_Click(对象发件人,EventArgs五)


我发现,这个解决方案是


  

的Response.Redirect(home.aspx,FALSE);
  但同样这个错误发生。


什么是一个很好的解决方案呢?

我的code片段:

 尝试
    {        小数金额= 0;
        Int64的CabId = 0;
        串CabName =;
        串CarImage =;        的foreach(在dtlstcars.Items的DataListItem GR)
        {
            //如果(e.Item.ItemType == || ListItemType.Item == e.Item.ItemType ListItemType.AlternatingItem)
            // {
            单选objcheck =(单选)gr.FindControl(rdbtncarchecked);
            如果(objcheck.Checked ==真)
            {
                文字ltrid =新的文字();
                ltrid =(文字)gr.FindControl(ltrid);                标签lbtaxiname =(标签)gr.FindControl(lbtaxiname);
                标签lbonewaycarprice =(标签)gr.FindControl(lbonewaycarprice);
                标签lbtwowaycarprice =(标签)gr.FindControl(lbtwowaycarprice);
                图像imgcar =(图)gr.FindControl(imgcar);                如果(ltrid = NULL&放大器;!&安培; lbtaxiname = NULL&放大器;!&安培; imgcar = NULL&放大器;!&安培; lbonewaycarprice = NULL&放大器;!&安培;!lbtwowaycarprice = NULL)
                {                    如果(lbrootype.Text ==1)
                    {
                        金额= Convert.ToDecimal(lbonewaycarprice.Text);
                    }
                    其他
                    {
                        金额= Convert.ToDecimal(lbtwowaycarprice.Text);
                    }
                }
                CabId = Convert.ToInt64(ltrid.Text);
                CabName = lbtaxiname.Text;
                CarImage = imgcar.ImageUrl;            }        }
   如果(lbroottype.Text =&的String.Empty放大器;!&安培;!lbrouteid.Text =&的String.Empty功放;&安培;!lbfrom.Text =&的String.Empty功放;&安培; lbpickupdate.Text =&的String.Empty放大器;!&安培; !lbto.Text =&的String.Empty功放;&安培; lbpickupdate.Text =&的String.Empty放大器;!&安培; lbpickuptime.Text =的String.Empty)!
        {            Session.Add(BookingDetail,BookingDetail(lbroottype.Text,Convert.ToInt64(lbrouteid.Text),lbfrom.Text,lbto.Text,Convert.ToDateTime(lbpickupdate.Text),lbpickuptime.Text,Convert.ToDateTime(lbreturndate。文本),的String.Empty,CabId,CabName,CarImage,金额txtPickupaddress.Text,txtDropaddress.Text,txtlandmark.Text,txtname.Text,ddmobilestd code.SelectedValue,txtmobileno.Text,ddalternatestd code.SelectedValue ,txtalternateno.Text,txtemail.Text,lbdays.Text)); // 3
            Session.Remove(购物车);            Session.Remove(editcart);
            的Response.Redirect(确认);
        }
        其他
        {
            的Response.Redirect(家);
        }
    }    赶上(例外EXT)
    {        弦乐味精= ext.Message;
        da.InsertRecordWithQuery(插入error_tbl值('+ MSG +'));
    }


解决方案

http://support.microsoft.com/kb/312629

你可以看到这里的问题是,你正试图在try / catch块中使用Response.Redirect。它抛出的异常。

您改变呼叫被解的Response.Redirect(网址,FALSE)应该工作。您需要确保做到每个Response.Redirect的电话。

另外请注意,这将继续执行,所以你必须处理(prevent它继续以其他方式)。

System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object stateInfo) at System.Web.HttpResponse.End() at System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
at System.Web.HttpResponse.Redirect(String url) at taxi_selection.lnkbtnconfirm_Click(Object sender, EventArgs e)

I found that the solution for this is

Response.Redirect("home.aspx",false); but again this error is occurring.

What is a good solution for this?

my code snippets :

try
    {

        Decimal Amount = 0;
        Int64 CabId = 0;
        String CabName = "";
        String CarImage = "";

        foreach (DataListItem gr in dtlstcars.Items)
        {
            //if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            //{
            RadioButton objcheck = (RadioButton)gr.FindControl("rdbtncarchecked");
            if (objcheck.Checked == true)
            {
                Literal ltrid = new Literal();
                ltrid = (Literal)gr.FindControl("ltrid");

                Label lbtaxiname = (Label)gr.FindControl("lbtaxiname");
                Label lbonewaycarprice = (Label)gr.FindControl("lbonewaycarprice");
                Label lbtwowaycarprice = (Label)gr.FindControl("lbtwowaycarprice");
                Image imgcar = (Image)gr.FindControl("imgcar");



                if (ltrid != null && lbtaxiname != null && imgcar != null && lbonewaycarprice != null && lbtwowaycarprice != null)
                {

                    if (lbrootype.Text == "One")
                    {
                        Amount = Convert.ToDecimal(lbonewaycarprice.Text);
                    }
                    else
                    {
                        Amount = Convert.ToDecimal(lbtwowaycarprice.Text);
                    }
                }
                CabId = Convert.ToInt64(ltrid.Text);
                CabName = lbtaxiname.Text;
                CarImage = imgcar.ImageUrl;



            }

        }
   if (lbroottype.Text != String.Empty && lbrouteid.Text != String.Empty && lbfrom.Text != String.Empty && lbpickupdate.Text != String.Empty && lbto.Text != String.Empty && lbpickupdate.Text != String.Empty && lbpickuptime.Text != String.Empty)
        {

            Session.Add("BookingDetail", BookingDetail(lbroottype.Text, Convert.ToInt64(lbrouteid.Text), lbfrom.Text, lbto.Text, Convert.ToDateTime(lbpickupdate.Text), lbpickuptime.Text, Convert.ToDateTime(lbreturndate.Text), String.Empty, CabId, CabName, CarImage, Amount, txtPickupaddress.Text, txtDropaddress.Text, txtlandmark.Text, txtname.Text, ddmobilestdcode.SelectedValue, txtmobileno.Text, ddalternatestdcode.SelectedValue, txtalternateno.Text, txtemail.Text, lbdays.Text));//3
            Session.Remove("cart");

            Session.Remove("editcart");
            Response.Redirect("confirm");
        }
        else
        {
            Response.Redirect("home");
        }


    }



    catch (Exception ext)
    {

        String msg = ext.Message;
        da.InsertRecordWithQuery("insert error_tbl values('" + msg + "')");
    }

解决方案

http://support.microsoft.com/kb/312629

as you can see here the problem is that you are attempting to use response.redirect in a try/catch block. It thrown an exception.

Your solution of changing the call to be Response.Redirect(url, false) should work. You need to make sure to do it on every Response.Redirect call.

Also note that this will continue execution, so you will have to handle that (prevent it from continuing in some other way).

这篇关于当我们使用线程已被中止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆