private ConcurrentBag<DataRow> _dataTableRows;
private DataTable _dataTable;
IList<PIPoint> points = PIPoint.FindPIPoints(_piServer, pointQuery).ToList();
PIPointList pointValues = new PIPointList(points);
AFListResults<PIPoint, AFValue> values = pointValues.CurrentValue();
Parallel.ForEach(values, value => {
IDcitionary<string, object> pointAttributes = value.PIPoint.GetAttributes();
DataRow row = ConfigureRow(pointAttributes, value); // this simply converts the 55 attributes & value (with timestamp) into the string columns for the data row
_dataTableRows.Add(row);
this.AddDataTableRecords(100000);
});
public void AddDataTableRecords(int threshold) {
if (_dataTableRows.Count >= threshold) {
lock (_dataTable.Rows.SyncRoot) {
foreach (DataRow row in _dataTableRows.Take(_dataTableRows.Count) {
_dataTable.Rows.Add(row);
}
bool success = _dataController.UpsertDataTableRecords(_dataTable);
if (success) {
_dataTable.Rows.Clear();
}
}
}
}
private ConcurrentBag<DataRow> _dataTableRows;
private DataTable _dataTable;
IList<PIPoint> points = PIPoint.FindPIPoints(_piServer, pointQuery).ToList();
PIPointList pointValues = new PIPointList(points);
AFListResults<PIPoint, AFValue> values = pointValues.CurrentValue();
Parallel.ForEach(values, value => {
IDcitionary<string, object> pointAttributes = value.PIPoint.GetAttributes();
DataRow row = ConfigureRow(pointAttributes, value); // this simply converts the 55 attributes & value (with timestamp) into the string columns for the data row
_dataTableRows.Add(row);
this.AddDataTableRecords(100000);
});
public void AddDataTableRecords(int threshold) {
if (_dataTableRows.Count >= threshold) {
lock (_dataTable.Rows.SyncRoot) {
foreach (DataRow row in _dataTableRows.Take(_dataTableRows.Count) {
_dataTable.Rows.Add(row);
}
bool success = _dataController.UpsertDataTableRecords(_dataTable);
if (success) {
_dataTable.Rows.Clear();
}
}
}
}