public void Test(Func <decimal> func, OperType type, Func <decimal> func_deposit = null) { Console.WriteLine(type.ToString()); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); List <Task <decimal> > tasks = new List <Task <decimal> >(); for (int i = 0; i < taskNum; i++) { tasks.Add(Task.Run <decimal>(func)); } if (func_deposit != null) { for (int i = 0; i < taskNum; i++) { tasks.Add(Task.Run <decimal>(func_deposit)); } } var result = Task.WhenAll(tasks); OutputResult(result.Result); stopwatch.Stop(); Console.WriteLine("cost time: " + stopwatch.Elapsed.TotalMilliseconds); Console.WriteLine(); }
private void RunOper() { try { Utils.ToCardLog("Запуск RunOper OperType=" + OperType.ToString() + " Amount= " + Amount.ToString()); OperInProcess = true; SAPacketObj Request = new SAPacketObj(); SAPacketObj Response = new SAPacketObj(); PCPOSTConnectorObj Conn = new PCPOSTConnectorObj(); Request.Amount = (Amount).ToString(); Request.OperationCode = OperType; Request.CurrencyCode = "643"; Request.DateTimeHost = DateTime.Now.ToString("yyyyMMddHHmmss"); //Conn.InitResources(); Conn.Exchange(ref Request, ref Response, 10); RespCode = Response.ResponseCodeHost.Trim(); Utils.ToCardLog(String.Format("[RunOper] Операция выполнена. Результат: {0}, TrxIDCRM {1}, TrxID {2}, ReferenceNumber {3}", RespCode, Response.TrxIDCRM, Response.TrxID, Response.ReferenceNumber)); try { Utils.ToCardLog(String.Format("[RunOper] Операция выполнена. Входящий запрос: {0}, TrxIDCRM {1}, TrxID {2}, ReferenceNumber {3}", RespCode, Request.TrxIDCRM, Request.TrxID, Request.ReferenceNumber)); } catch { } Receipt = ReadChequeFile(); if (((RespCode == "00") || (RespCode == "000")) && (!Receipt.ToUpper().Contains("НЕ ОПЛАЧИВАТЬ"))) { if ((OperType == 1) || (OperType == 4)) { string Tmp = Receipt; if (!iniFile.Arcus2PrintOneSlip) { Tmp += Convert.ToChar(31) + Environment.NewLine; Tmp += Receipt; Receipt = Tmp; } try { Utils.ToCardLog("[RunOper] Добавляю Слип в Файл."); ArcusSlips AS = Arcus2DataFromXML.ReadArcusSlips(); DateTime HDT = DateTime.Now; try { HDT = Convert.ToDateTime(Response.DateTimeCRM); } catch { } ArcusSlip S = new ArcusSlip() { HostDt = HDT, Sum = Convert.ToDecimal(Response.Amount), Void = (Response.OperationCode == 4), Num = Response.TrxIDCRM, RRN = Response.ReferenceNumber, AlohaCheckId = AlohaCheckId, AlohaCheckShortNum = AlohaCheckShortNum }; string[] Str = Receipt.Split(char.ConvertFromUtf32(10)[0]); foreach (string str in Str) { Utils.ToCardLog(str); S.Slip.Add(str); } decimal SummFromTxt = GetSummFromSlip(S.Slip); if ((SummFromTxt != 0) && (S.Sum != SummFromTxt * 100)) { Utils.ToCardLog("Error Разные суммы в слипе " + SummFromTxt.ToString() + " и ответе от терминала. " + S.Sum.ToString()); S.Sum = SummFromTxt * 100; } AS.Slips.Add(S); Arcus2DataFromXML.WriteArcusSlips(AS); Utils.ToCardLog("[RunOper] Добавлил Слип в Файл."); } catch (Exception e) { Utils.ToCardLog("[Error] Ошибка добавления слипа в файл." + e.Message); } } } else { try { EventSenderClass.SendAlohaAsincEvent(StopListService.AlohaEventType.ErrorCreditCardterminal, "", AlohaTSClass.AlohaCurentState.WaterId, AlohaTSClass.GetJobCode(AlohaTSClass.AlohaCurentState.WaterId), "", Convert.ToInt32(RespCode), (int)AlohaTSClass.AlohaCurentState.TableId, (int)AlohaTSClass.AlohaCurentState.CheckId); } catch { } } resOper = GetCodeDescr(RespCode); if (!Sinc) { RunOperationAsincComplitedVoid(OperType, RespCode, resOper, "", Receipt); } OperInProcess = false; Utils.ToCardLog("Отработал RunOper OperType=" + OperType.ToString() + " Amount= " + Amount.ToString()); } catch (Exception e) { resOper = "Ошибка программы. " + e.Message; RespCode = "-1"; if (!Sinc) { RunOperationAsincComplitedVoid(OperType, RespCode, resOper, "", ""); } Utils.ToCardLog("[Error] Запускa RunOper " + e.Message); } }