Click here to Skip to main content
15,881,044 members
Please Sign up or sign in to vote.
1.40/5 (2 votes)
See more:
I got one bug confused me long time,still not fix it.Anyone can help ?
C#
private string ppcManageShortSales(string strData)
       {
List<salesresultppc> listSalesResultPPC = new List<salesresultppc>();
                            string[] arrSalesInfo = salesInfo.Split('`');
                            var sales = new salesInfoPPC[arrSalesInfo.Length];
                            string[] arrRawData = new string[arrSalesInfo.Length];//luo add Aug 28,2013
                            int taskIndex = 0;
                            for (int tt = 0; tt < arrSalesInfo.Length; tt++)
                            {
                                salesInfoPPC sippc = new salesInfoPPC();
                                sippc.strDataResource = strDataResouce;
                                sippc.payout = payout;
                                sippc.dtSalesDetail = createSalesDetailTable();
                                sippc.drawdate = arrSelectedDrawDate[0];
                                sippc.listHotDigit = listHotDigit;
                                sippc.salesInfo = arrSalesInfo[tt];
                                sippc.tempPlayMethodArrangeId = tempPlayMethodArrangeId;
                                sippc.salesIndex = tt;//luo add Aug 28,2013
                                sales[taskIndex] = sippc;
                                taskIndex++;
                            }
Parallel.ForEach(sales, (salesInfoPPC) => listSalesResultPPC.Add(ppcManageShortSalesHelper(salesInfoPPC)));

                   foreach (var result in listSalesResultPPC)
                           {
                               if (result.effect.Equals(0))
                               {
                                   effect = result.effect;
                                   strMessage = result.strMessage;
                                   total_amount += result.GrandTotal;
                                   dtSalesDetail.Merge(result.subSalesDetail);
                                   dtSumExcessDigit.Merge(result.subSumExcessDigit);
                                   dtSumHotDigit.Merge(result.subSumHotDigit);
                                   dtSumHotDigitAgent.Merge(result.subSumHotDigitAgent);
                                   hot_updateSql.Append(result.strSumHotDigitUpdateSql);
                                   updateSql.Append(result.strSumExcessDigitUpdateSql);
                                   //sbRawData.Append(result.RawValue);//old
                                   arrRawData[result.salesIndex] = result.RawValue;//luo add Aug 28,2013
                                   if (!intExistForceInsert.Equals(1))
                                       intExistForceInsert = result.intExistForceInsert;
                                   if (customerBalance.Equals(0))
                                       customerBalance = result.customerBalance;
                                   if (custId.Equals(0))
                                       custId = result.custId;
                                   customerName = result.customer;
                               }
                               else
                               {
                                   effect = result.effect;
                                   strMessage = result.strMessage;
                                   break;
                                   //intExistForceInsert = result.intExistForceInsert;
                               }
                           }

if (Main.ctsDetail.IsCancellationRequested)
                                    {
                                        Main.countTaskRunTimesDetail = 0;
                                        Main.ctsDetail = new CancellationTokenSource();
                                        Task.Factory.StartNew(ProcessQueueDetail, Main.ctsDetail.Token);
                                    }
                                    if (Main.detailQueue == null)
                                        Main.detailQueue = new Queue<datatable>();
                                    Main.detailQueue.Enqueue(dtSalesDetail);//dtSalesDetail add to the detailQueue,waiting for ProcessQueueDetail()method deal

                                    #region summary hot & excess digit tasks
                                    if (dtSumHotDigit.Rows.Count > 0)
                                        Task_InsertSummaryHotDigit(dtSumHotDigit);

                                    if (dtSumHotDigitAgent.Rows.Count > 0)
                                        Task_InsertSummaryHotDigitAgent(dtSumHotDigitAgent);

                                    Task task3 = null;//this one is ok
                                    ctsExcessDigitInsert = new CancellationTokenSource();
                                    if (dtSumExcessDigit.Rows.Count > 0)
                                        task3 = Task.Factory.StartNew(() => Task_InsertSummaryExcessDigit(dtSumExcessDigit), ctsExcessDigitInsert.Token);

                                    if (hot_updateSql.ToString().Length > 0)
                                        Task_UpdateSummaryHotDigit(hot_updateSql.ToString());

                                    ctsExcessDigitUpdate = new CancellationTokenSource();
                                    Task task5 = null;//this one is ok
                                    if (updateSql.ToString().Length > 0)
                                        task5 = Task.Factory.StartNew(() => Task_UpdateSummaryExcessDigit(updateSql.ToString()), ctsExcessDigitUpdate.Token);
                                    #endregion
}

private salesResultPPC ppcManageShortSalesHelper(salesInfoPPC salesInfoppc)
{
return new salesResultPPC{}
}

Current have 5 users use this service,so anyone can help?
waiting for u.
thx.
Posted
Updated 22-Sep-13 4:48am
v2
Comments
Paulo Zemek 22-Sep-13 10:58am    
I can't compile such code as it references methods that aren't present here.
But in the title you say that you have an AggregateException. Can't you see the inner exceptions and their stack-traces? Maybe by seeing the stacktrace you will go directly to the line that's causing the exception.
If you are able to cause the bug while debugging, you may activate exceptions to be shown when thrown and not only when they aren't caught.
littleluoron 22-Sep-13 21:09pm    
Thanks your reply,Paulo Zemek.
This code just part of my projec t.
If can debugging then i can catch this bug,but the problem is debug no problem,and before only 3 users using at the same time no problem,but add one user in,then got this bug.
So i scare should be my code wrong about "Task".
Paulo Zemek 22-Sep-13 21:25pm    
I am not sure about which objects are global and which are local. For example, if your Main.detailQueue is shared between the different tasks, then locks should be used (after all, tasks are different threads, so you should not update a shared object by multiple threads without lock).
littleluoron 22-Sep-13 21:35pm    
Okie,let me check my code again.
Thanks.

1 solution

Hello

AggregateException is an exception that contains all the individual exceptions thrown on all threads.

So basically something went wrong one or several threads and some exceptions were thrown in
C#
Parallel.ForEach(sales, (salesInfoPPC) => listSalesResultPPC.Add(ppcManageShortSalesHelper(salesInfoPPC)));


You can catch the AggregateException and use it's Handle method to know what the problem was.

C#
catch (AggregateException ae) {
    ae.Handle((x) =>
    {
        if (x is ArgumentNullException)
        {
           // manage the exception.
           return true; // do not stop the program
        }
        else if (x is UnauthorizedAccessException) 
        {
            // manage the access error.
            return true;
        }
        // else if any other exceptin type you want to handle. etc...

        else is (Exception ex)
        {
            // Any other exception here
        }
        return false; // Let anything else stop the application.
    });
}



Valery.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900