Accessing aggregate PIValues is very slow in a worker thread

Discussion created by isolutions on Apr 16, 2010
Latest reply on Apr 20, 2010 by isolutions

Hi, I am working on multithreaded C# WinForm application to process PIValues. The performance is very bad when processing aggregate PIValues in a worker thread. I wrote a piece of code as shown below to test the performance.


The rate to access the timestamps in aggregate PIValues in an worker thread is about 80 values per second while the rate for accessing recorded PIValues is about 11,000 values per second. If I run this testing code in the main thread, both rates are about the same as 11,000 values per second. Could anyone please let me know what is wrong? Any help is very appreciated.

void Test()
    // Average
    PISDKCommon.NamedValues namedValues = ((PISDK.IPIData2)point.Data).Summaries2(
         startTime, endTime, timeStep, PISDK.ArchiveSummariesTypeConstants.asAverage,
         PISDK.CalculationBasisConstants.cbTimeWeighted, piAsyncStatus);

    object obj = "Average";
    PISDK.PIValues myValues = (PISDK.PIValues)namedValues.get_Item(ref obj).Value;
    double dblValue;
    DateTime dt1 = DateTime.Now;
    double utcSeconds;

    for (int i = 1; i <= myValues.Count; i++)
        utcSeconds = myValues.TimeStamp.UTCSeconds;

    DateTime dt2 = DateTime.Now;
    TimeSpan ts = dt2.Subtract(dt1);
    double rate1 = myValues.Count / ts.TotalSeconds;

    // Recorded values
    myValues = point.Data.RecordedValues(
           startTime, endTime, PISDK.BoundaryTypeConstants.btInside, "",
           PISDK.FilteredViewConstants.fvRemoveFiltered, piAsyncStatus);

    dt1 = DateTime.Now;
    for (int i = 1; i <= myValues.Count; i++)
        utcSeconds = myValues.TimeStamp.UTCSeconds;

    dt2 = DateTime.Now;
    TimeSpan ts2 = dt2.Subtract(dt1);
    double rate2 = myValues.Count / ts2.TotalSeconds;