我在asp.net/ajax调用中有一个长时间运行的进程。在进程结束时,我将结果分配给Label,但是当进程完成时,服务器似乎无法再分配给Label(就好像响应已经在结束之前发送一样)处理)。
我正在使用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";
}
}
}