Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 按用户输入或无响应取消方法_C#_Asp.net - Fatal编程技术网

C# 按用户输入或无响应取消方法

C# 按用户输入或无响应取消方法,c#,asp.net,C#,Asp.net,我工作的网站允许用户在用户选择的两个日期之间生成报告。我遇到的问题是,如果一个用户在一个巨大的日期差异(即一年)之间意外请求报告,服务器将承受很大的压力,有时可能会对所有用户造成崩溃。我要做的是有一个进度条,向用户显示报告要花多长时间,还有一个取消按钮或一个检查按钮,看看它们是否还在。我正在考虑在任务中使用取消令牌,但不确定这是否是我想要的。我们还考虑了一个全局链接列表,其中随机数链接到true-false,因为用户可以同时打开多个报告。我在下面包含了一些相关代码。如果您能给我提供任何帮助或正确

我工作的网站允许用户在用户选择的两个日期之间生成报告。我遇到的问题是,如果一个用户在一个巨大的日期差异(即一年)之间意外请求报告,服务器将承受很大的压力,有时可能会对所有用户造成崩溃。我要做的是有一个进度条,向用户显示报告要花多长时间,还有一个取消按钮或一个检查按钮,看看它们是否还在。我正在考虑在任务中使用取消令牌,但不确定这是否是我想要的。我们还考虑了一个全局链接列表,其中随机数链接到true-false,因为用户可以同时打开多个报告。我在下面包含了一些相关代码。如果您能给我提供任何帮助或正确的方向,我将不胜感激,谢谢

//java脚本,该脚本从和太日期传递,并调用方法genonereport

window.open('genonereport?idd=' + idd + '&fromm=' + 
fromm + '&too=' + too + '&filetype=' + outputValue ,
 '_blank'); 
//genonereport将值传递给下面包含相关方法的类 ---report.render如果用户取消报告或离开,我希望取消的方法是哪个

     public byte[] genReportBytes(int id, string fromm, string too, string filetype)
    {

        reportDetails repD = new reportDetails();
        repD = getOneReport(id);

        LocalReport report = new LocalReport();

        if (fromm != null)
            repD.ParametersCommandLine = "@startdate=" + fromm;

        if (too != null)
            repD.ParametersCommandLine += " @enddate=" + too;

        string RDLCPath = ConfigurationManager.AppSettings["RDLCPath"];
        string ReportOutputPath = ConfigurationManager.AppSettings["ReportOutputPath"];

        string RDLCName = repD.RDLCName;
        RDLCPath += @"\" + RDLCName;
        report.ReportPath = RDLCPath;

        string sqlGet = repD.SQLOfReport;

        report.DataSources.Add(new ReportDataSource(repD.DatasetName, getReportData(sqlGet, repD.ParametersCommandLine)));

        // export to byte array

        Warning[] warnings;
        string[] streamids;
        string mimeType;
        string encoding;
        string filenameExtension;
        string deviceInf = "";
        byte[] bytes = new byte[64];
        byte[] empty = null; 
        string extension;
        bool Completed;

        if (filetype == "pdf")
        {
            deviceInf = "<DeviceInfo><PageHeight>8.5in</PageHeight><PageWidth>11in</PageWidth><MarginLeft>0in</MarginLeft><MarginRight>0in</MarginRight></DeviceInfo>";
            //fileName = ReportOutputPath + @"\" + repD.NameOfOutputPDF + ".PDF";
            //Completed = ExecuteWithTimeLimit(TimeSpan.FromMilliseconds(5000), () =>
            //{
                bytes = report.Render("pdf", deviceInf, out mimeType, out encoding, out filenameExtension,
                                        out streamids, out warnings);
            //});

        }
        else
        {
            //fileName = ReportOutputPath + @"\" + repD.NameOfOutputPDF + ".XLS";
            //Completed = ExecuteWithTimeLimit(TimeSpan.FromMilliseconds(5000), () =>
            //{
            bytes = report.Render(
                  "Excel");
            //});
        }
        //if (Completed == true)
        //{
            return bytes;
        //}
        //else
            //return empty;
    }

对于冗长的问题,非常抱歉,再次感谢

您将需要至少三个web端点:

  • 其中一个用于生成报告并返回结果
  • Javascript可以定期请求它来检查进度
  • 您的浏览器可以请求取消该任务
  • 您需要在字典中使用某种id存储每个任务的句柄,以便将id传递到查询2和查询3中

    给你一个如何做的例子


    这并不简单,因此限制用户可以生成的报告的大小可能是首选选项。

    作为第一步,为什么不将用户可以选择的时间跨度限制为6个月呢?不幸的是,有时用户确实需要跨越一年的报告,因为有些报告是汇总报告,只汇总每天的数据,并且不需要很长时间即可呈现。但是,如果用户运行一年的每日报告,其中每给定一天包含10分钟的值间隔,并且图形问题开始出现,那么如果您有办法确定用户希望运行哪种类型的报告(摘要或不摘要),您可以限制日期。。e、 g.对于crystal reports,您仅在选择报告后输入参数。。。也许你也可以这样做。。。选择一个摘要。。。让用户指定日期。。。选择一个每日。。。让用户指定有限制的日期。“报告需要多长时间”您怎么可能估计?当考虑到网络争用、数据库可用性、cpu工作负载等因素时,会读取
    public static bool ExecuteWithTimeLimit(TimeSpan timeSpan, Action codeBlock)
        {
            try
            {
                Task task = Task.Factory.StartNew(() => codeBlock());
                task.Wait(timeSpan);
                return task.IsCompleted;
            }
            catch (AggregateException ae)
            {
                throw ae.InnerExceptions[0];
            }
        }