Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.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_Function_Abort - Fatal编程技术网

C# 单击按钮时中止正在运行的函数

C# 单击按钮时中止正在运行的函数,c#,asp.net,function,abort,C#,Asp.net,Function,Abort,我有一个网页,它有一个功能,当我们点击pdf时,它会在移动中获取打印机的值。这需要一些时间,所以反复点击,网页崩溃 是否有任何方法可以中止函数的当前运行,或者在单击后以某种方式禁用按钮单击 用户界面代码: <asp:UpdatePanel ID="UpdatePanel2" runat="server"> <Triggers> <asp:PostBackTrigger ControlID="imgExportPDF" /> </Tri

我有一个网页,它有一个功能,当我们点击pdf时,它会在移动中获取打印机的值。这需要一些时间,所以反复点击,网页崩溃

是否有任何方法可以中止函数的当前运行,或者在单击后以某种方式禁用按钮单击

用户界面代码:

 <asp:UpdatePanel ID="UpdatePanel2" runat="server">
    <Triggers>
 <asp:PostBackTrigger ControlID="imgExportPDF" />
    </Triggers>
<ContentTemplate>
        <table id="topHeading" width="100%" cellspacing="0" cellpadding="0" border="0" class="PageHeader">
            <tr align="center" style="height: 25px" class="PageHeader2">
                <td>
                    &nbsp;
                </td>
                <td align="right" valign="bottom" style="width: 30%" visible="false">
                <asp:ImageButton ID="imgExportPDF" runat="server" ImageUrl="~/Images/pdf-Export.jpg"

                </td>
            </tr>
        </table>
    </ContentTemplate>
</asp:UpdatePanel>

0)
{
对于(int i=0;i0)
{
countData=dsDev.Tables[0]。Rows.Count+Convert.ToInt32(dsDev.Tables[1]。Rows[0][“AdionalRows1”].ToString())+Convert.ToInt32(dsDev.Tables[2]。Rows[0][“AdionalRows2”].ToString());
PdfDocument myPdfDocument=新PdfDocument(PdfDocumentFormat.A4);
PdfTable myPdfTable=myPdfDocument.NewTable(新字体(“Verdana”,8),countData+counterAdd,2,4);
myPdfTable.ImportDataTable(returnTable(dsDev、deviceCounter、sb.ToString());
//设置PDF表格样式
myPdfTable.HeadersRow.SetFont(新字体(“Arial”,8,FontStyle.Bold));
myPdfTable.HeadersRow.SetColor(System.Drawing.Color.Gray,System.Drawing.Color.Gray);
myPdfTable.SetColors(Color.Black,Color.White,Color.White);
myPdfTable.setboorders(Color.Gray,1,BorderType.CompleteGrid);
myPdfTable.SetColumnsWidth(新的int[]{30,30});
int[]arrayDevice=listDevice.ToArray();
for(int m=0;mprotected void imgExportPDF_Click(object sender, ImageClickEventArgs e)
{

    saveDetails();

    int counterAdd = 0;

    DataSet dsDevNotReady = CDBIntract.GetDevNotReady(EnterpriseV, CDInfonew.Count);
    if (dsDevNotReady != null)
    {
        if (dsDevNotReady.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < dsDevNotReady.Tables[0].Rows.Count; i++)
            {
                sb.Append((deviceCounter + 1) + ". IP Address : " + dsDevNotReady.Tables[0].Rows[i]["IPAddress"].ToString() + "  And Model Name : " + dsDevNotReady.Tables[0].Rows[i]["Model"].ToString() + "  On Date : " + DateTime.Now.ToString() + " " + dsDevNotReady.Tables[0].Rows[i]["Info"].ToString());
                sb.Append("\r\n");
                deviceCounter++;
            }
            counterAdd++;
        }
    }

    int countData = 0;
    DataSet dsdev= CDBIntract.Blah(EnterpriseV, CDInfonew.Count);

    if (dsDev != null)
    {

        if (dsDev.Tables[0].Rows.Count > 0)
        {
            countData = dsDev.Tables[0].Rows.Count + Convert.ToInt32(dsDev.Tables[1].Rows[0]["AditionalRows1"].ToString()) + Convert.ToInt32(dsDev.Tables[2].Rows[0]["AditionalRows2"].ToString());
            PdfDocument myPdfDocument = new PdfDocument(PdfDocumentFormat.A4);
            PdfTable myPdfTable = myPdfDocument.NewTable(new Font("Verdana", 8), countData + counterAdd, 2, 4);
            myPdfTable.ImportDataTable(returnTable(dsDev, deviceCounter, sb.ToString()));

            //Set PDF Table Style
            myPdfTable.HeadersRow.SetFont(new Font("Arial", 8, FontStyle.Bold));
            myPdfTable.HeadersRow.SetColors(System.Drawing.Color.Gray, System.Drawing.Color.Gray);
            myPdfTable.SetColors(Color.Black, Color.White, Color.White);
            myPdfTable.SetBorders(Color.Gray, 1, BorderType.CompleteGrid);

            myPdfTable.SetColumnsWidth(new int[] { 30, 30 });
            int[] arrayDevice = listDevice.ToArray();
            for (int m = 0; m < arrayDevice.Length; m++)
            {
                try
                {
                    foreach (PdfCell pc in myPdfTable.CellRange(arrayDevice[m], 0, arrayDevice[m], 0).Cells)
                    {
                        pc.ColSpan = 2;
                        pc.SetCellPadding(4);
                        pc.SetColors(Color.Red, Color.LightGray);
                        pc.SetFont(new Font("Arial", 10, FontStyle.Bold));
                    }
                }
                catch (Exception ex)
                { }
            }
            int[] array = list.ToArray();
            for (int m = 0; m < array.Length; m++)
            {
                try
                {
                    foreach (PdfCell pc in myPdfTable.CellRange(array[m], 0, array[m], 0).Cells)//(0//,0//,0//Number of rows,0//column)
                    {
                        pc.ColSpan = 2;
                        pc.SetCellPadding(4);
                        pc.SetColors(Color.Blue, Color.LightGray);
                        pc.SetFont(new Font("Arial", 10, FontStyle.Bold));
                    }
                }
                catch (Exception ex)
                { }
            }
            int[] array1 = list2.ToArray();
            for (int n = 0; n < array1.Length; n++)
            {
                try
                {
                    foreach (PdfCell pc in myPdfTable.CellRange(array1[n], 0, array1[n], 0).Cells)//(0//,0//,0//Number of rows,0//column)
                    {
                        pc.ColSpan = 2;
                        pc.SetCellPadding(4);
                        pc.SetColors(Color.Blue, Color.LightGray);
                        pc.SetFont(new Font("Arial", 8, FontStyle.Bold));
                    }
                }
                catch (Exception ex)
                { }
            }
            int[] array2 = list3.ToArray();
            for (int k = 0; k < array2.Length; k++)
            {
                try
                {

                    foreach (PdfCell pc in myPdfTable.CellRange(array2[k], 0, array2[k], 0).Cells)//(0//,0//,0//Number of rows,0//column)
                    {
                        pc.ColSpan = 2;
                        pc.SetCellPadding(4);
                        //pc.SetColors(Color.Blue, Color.LightGray);
                        if (k == 0)
                            pc.SetFont(new Font("Arial", 8, FontStyle.Bold));
                    }
                }
                catch (Exception ex)
                {
                }
            }
            myPdfTable.SetRowHeight(100);
            // Now we set some alignment... for the whole table and then, for a column.
            myPdfTable.SetContentAlignment(ContentAlignment.MiddleLeft);

            string logo = HttpContext.Current.Server.MapPath(".") + "/images/Printeaze_Logo02.jpg";
            PdfImage LogoImage = myPdfDocument.NewImage(logo);

            string companylogo = HttpContext.Current.Server.MapPath(".") + "/images/CompanyLogo.jpg";
            PdfImage CompanyLogo = myPdfDocument.NewImage(companylogo);

            int i = 0;
            PdfTablePage newPdfTablePage;

            // Here we start the loop to generate the table...
            while (!myPdfTable.AllTablePagesCreated)
            {
                // we create a new page to put the generation of the new TablePage:
                i++;

                PdfPage newPdfPage = myPdfDocument.NewPage();

                if (i == 1)
                {

                    newPdfTablePage =
                        myPdfTable.CreateTablePage(new PdfArea(myPdfDocument, 18, 120, 560, 680));
                    // newPdfTablePage =
                    //     myPdfTable.CreateTablePage(new PdfArea(myPdfDocument, 18, 120, 560, 450));

                    newPdfPage.Add(LogoImage, 460, 30, 120);
                    newPdfPage.Add(CompanyLogo, 20, 20, 120);
                    // we also put a Label 
                    PdfTextArea pta = new PdfTextArea(new Font("Verdana", 16, FontStyle.Bold), Color.Black
                        , new PdfArea(myPdfDocument, 20, 70, 350, 20), ContentAlignment.MiddleLeft, "Blah");

                    newPdfPage.Add(newPdfTablePage);
                    newPdfPage.Add(pta);
                    //PointF pointstart = new PointF(20, 140);
                    //PointF pointend = new PointF(578, 140);
                }
                else
                {
                    newPdfTablePage = myPdfTable.CreateTablePage(new PdfArea(myPdfDocument, 18, 15, 560, 800));
                    // newPdfTablePage = myPdfTable.CreateTablePage(new PdfArea(myPdfDocument, 18, 15, 600, 650));
                    newPdfPage.Add(newPdfTablePage);
                }

                newPdfPage.SaveToDocument();
            }
            // Finally we save the docuement...
            //myPdfDocument.SaveToFile("PDF.pdf");
            MemoryStream stream = new MemoryStream();
            myPdfDocument.SaveToStream(stream);
            Response.ClearHeaders();
            Response.ClearContent();
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment; filename= Blah.pdf");
            Response.BinaryWrite(stream.ToArray());
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
    }
}
HttpContext.Current.Session