0

首先,我是 C# 编程的新手,当我以 PDF 格式生成水晶报告时,我正面临无法评估表达式,因为代码已优化或本机框架位于调用堆栈顶部我已经搜索过在谷歌的答案,也看到了很多链接,包括这个,但没有任何帮助我谁能告诉我会是什么错误

我试过的代码是,

  protected void getpkeybt_Click(object sender, EventArgs e)
{
    bool ch = checkFromToDate();
    int i=checkTxt();
    if ( ch == true && i==1)
    {
        try
        {
            Response.Buffer = false;
            Response.ClearContent();
            Response.ClearHeaders();
            ReportDocument rpt = new ReportDocument();
            DateTime dt = DateTime.Parse(frmtxtdt.Text);
            DateTime dt1 = DateTime.Parse(frmtxtdt.Text);
            string frtxt = String.Format("{0:MM-dd-yyyy}", dt);
            string totxt = String.Format("{0:MM-dd-yyyy}", dt1);
            DataSet ds = Namespace.SP.EStoredprocedure(frtxt,totxt).GetDataSet();
            if (!IsPageRefresh)
           {
            if (ds.Tables[0].Rows.Count > 0
                && frtxt == ds.Tables[0].Rows[0]["Date"].ToString()
                && totxt == ds.Tables[0].Rows[0]["Date"].ToString())
            {
                ds.Tables[0].TableName = "Passkeys";

                ds.WriteXml(Server.MapPath("~/XML/Passkeys.xml"));
                string filename = Server.MapPath("~/Upload/Pkey_rpt.rpt");
                rpt.Load(filename);
                rpt.SetDataSource(ds);
                rpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Passkeys");

            }
            else if(frmtxtdt.Text.Trim() !=null && totxtdt.Text.Trim()!=null)
            {
                if (frtxt   == ds.Tables[0].Rows[0]["Date"].ToString()
                     && totxt == ds.Tables[0].Rows[0]["Date"].ToString() 
                     && ds.Tables[0].Rows.Count == 0)
                {

                    lblmsg.Text = "Pass Key(s) Not Yet Delivered for the Selected Date...";

                }
                else
                {

                    lblmsg.Text = "There is No Schedule for the Selected date....";
                }

            }
         }

        }
        catch (Exception ex)
        {
            lblmsg.Text = ex.Message;
        }
    }

}
4

1 回答 1

0

您的问题是ExportToHttpResponse()调用Response.End(),它以最快的方式结束响应:通过中止线程。那冒泡 a ThreadAbortException,您try/catch正在处理。但是,线程中止异常的问题在于它们默认情况下会在catch块的末尾自动重新抛出。这对你来说是个问题,因为你实际上并不希望这个线程被杀死(我猜它是你的 UI 线程。)因此,你需要调用Thread.ResetAbort()你的catch块,它指示运行时停止重新抛出例外。

请注意,通常建议这样做(既不从天空中止线程,也不在中止发生时停止中止。)但是,这是两者的已知“功能”,尤其是Response.End()一般ExportToHttpResponse()情况下,所以在你的情况下,我认为这是有道理的。

于 2013-06-11T05:16:49.773 回答