0

asp.net/ajax 呼び出しで実行時間の長いプロセスがあります。プロセスの最後に結果をラベルに割り当てていますが、プロセスが完了するまでに、サーバーがラベルに割り当てることができなくなったように見えます (応答が終了する前に既に送信されているかのように)処理する)。

私は updatepanel を使用して ajax 呼び出しを管理しています。これを解決する方法はありますか?

private void RunFNBOMultiThreaded()
    {
        lblFNBOCalcResult.Text = "";
        DAL dal = new DAL();
        int month = int.Parse(Request.QueryString["m"]);
        int year = int.Parse(Request.QueryString["y"]);
        if (dal.ImportExists(month, year, "fnbo"))
        {
            DataTable dt = dal.GetFNBOMIDs(month, year);
            DataTable groups = dal.GetChargeTypeGroupLookup();

            BankFNBO[] bankArray = new BankFNBO[NUMBER_OF_THREADS];
            DataTable[] dtArray = new DataTable[NUMBER_OF_THREADS];

            int division = dt.Rows.Count / NUMBER_OF_THREADS;
            int remainder = dt.Rows.Count % division;

            // split the cynergy import file into as many sections as we declare threads.
            for (int i = 0; i < NUMBER_OF_THREADS; i++)
            {
                switch (i + 1)
                {
                    case 1:
                        dtArray[i] = dt.AsEnumerable().Take(division).CopyToDataTable();
                        break;
                    case 2:
                        dtArray[i] = dt.AsEnumerable().Skip(division).Take(division).CopyToDataTable();
                        break;
                    case NUMBER_OF_THREADS:
                        // add the remainder to the last datatable. (division + remainder)
                        dtArray[i] = dt.AsEnumerable().Skip(division * i).Take(division + remainder).CopyToDataTable();
                        break;
                    default:
                        dtArray[i] = dt.AsEnumerable().Skip(division * i).Take(division).CopyToDataTable();
                        break;
                }
            }

            // One event is used for each bank object
            ManualResetEvent[] doneEvents = new ManualResetEvent[NUMBER_OF_THREADS];

            // Configure and launch threads using ThreadPool:
            for (int i = 0; i < NUMBER_OF_THREADS; i++)
            {
                doneEvents[i] = new ManualResetEvent(false);
                BankFNBO b = new BankFNBO(month, year, dtArray[i], groups, doneEvents[i]);
                bankArray[i] = b;
                ThreadPool.QueueUserWorkItem(b.ThreadPoolCallback, i);
            }

            try
            {
                // Wait for all threads in pool to calculate...
                WaitHandle.WaitAll(doneEvents);
                lblFNBOCalcResult.ForeColor = System.Drawing.Color.Green;
                lblFNBOCalcResult.Text = "Calculation was successful";
            }
            catch (Exception)
            {
                lblFNBOCalcResult.ForeColor = System.Drawing.Color.Red;
                lblFNBOCalcResult.Text = "Calculation failed";
            }
        }
    }
4

0 に答える 0