我有一个foreach。
它只将数据放入数据表中 但它会有例外。
如何解决?
感谢
[Smooch initWithSettings:[SKTSettings settingsWithAppId:@"Your App token(Get it from Smooch dashboard)"] completionHandler:^(NSError * _Nullable error, NSDictionary * _Nullable userInfo) {}
[[SKTUser currentUser] addProperties:@{@"Company":[[NSUserDefaults standardUserDefaults] valueForKey:@"company"],@"UserId":[[NSUserDefaults standardUserDefaults] valueForKey:@"empid"]}];
[Smooch show];
我一直得到以下例外:
System.AggregateException:发生了一个或多个错误。 ---> System.ArgumentOutOfRangeException: 参数名称:index
Parallel.ForEach(this.dt.AsEnumerable(), opt, r =>
string inTime = string.Empty;
string outTime = string.Empty;
string shiftID = string.Empty;
string shiftintime = string.Empty;
string shiftouttime = string.Empty;
decimal leaveHours = 0;
string tempNight = string.Empty;
CommandAPI_Prg.GetShiftID(r["EmployeeID"].ToString(), r["CDate"].ToDateTime(), out shiftID); // 取班別
CommandAPI_Prg.LogBoxTime(Env.User.Factory, r["EmployeeID"].ToString(), r["CDate"].ToDateTime(), out inTime, out outTime); // 取刷卡時間
CommandAPI_Prg.DayOfShift2(shiftID, out shiftintime, out shiftouttime); // 取班別時間
DataTable dayOfLeave = CommandAPI_Prg.DayOfLeave(Env.User.Factory, r["EmployeeID"].ToString(), r["CDate"].ToDateTime()); // 取請假資訊
DataTable dayOfOverTime = CommandAPI_Prg.DayOfOverTime(Env.User.Factory, r["EmployeeID"].ToString(), r["CDate"].ToDateTime()); // 取加班資訊
r["ShiftID"] = shiftID; // 實際班表
r["shiftintime"] = shiftintime;
r["shiftouttime"] = shiftouttime;
r["InTime"] = inTime;
r["OutTime"] = outTime;
}
);
如果重复Is Parallel.forEach(DataTable.AsEnumerable()线程安全
所以我不能使用Parallel.ForEach?