1 Reply Latest reply on Apr 6, 2015 3:14 PM by dng

    Is there a way to make sure all the events for a tag were deleted before continue with PI AFSDK?

    rsun

      I was trying to delete PI Data Archive events for a tag with PI AF SDK. All the code got executed, but I found out that the events were still existed within the PI Data Archive upon checking with PI SMT Archive editor. However, after waiting a couple of minutes, all the events for the specified tag got deleted between the time range. I could put sleep method before continue, but is there a method to use to make sure all the events for a tag were deleted before continue execute to the next tag? Thank you.

       

      PIServer server = new PIServers()["PISERVERNAME"];

      PIPoint tag = PIPoint.FindPIPoint(server, "TAGNAME");

      AFTimeRange timeRange = new AFTimeRange("StartTime", "EndTime");

      AFValues tagValues = tag.RecordedValues(timeRange, OSIsoft.AF.Data.AFBoundaryType.Inside, "", false, Int32.MaxValue);

      List<AFValue> list = new List<AFValue>();

      foreach (AFValue tagValue in tagValues)

      tag.UpdateValues(list, AFUpdateOption.Remove);

       

      Message was edited by: Ricky Sun

        • Re: Is there a way to make sure all the events for a tag were deleted before continue with PI AFSDK?
          dng

          Hi Ricky,

           

          AF SDK calls are synchronous, provided that you are not making multi-threaded/parallel calls. This means that the application will wait until UpdateValues to finish before moving on to the next statement. With that said, there are several other factors in play before you will be able to see the change reflected in PI SMT.

          • PI Buffer Subsystem: depending on how many events you are removing at a time, PI buffer subsystem might queue up events to be removed. In that case, your UpdateValues operation will complete but events are still in the buffer queue.
          • If you don't have buffering on, events will queue up in the event queue before getting committed into the archive.

           

          Can you also let me know your use case? Why would you like to delete all events for a tag before the next one? Perhaps we can suggest an alternative workaround.

           

          One solution (to ensure that all events are deleted) would be to query for the last AF value in the time range repeatedly until it cannot be retrieved anymore.

           

          FYI: I have moved this discussion to PI Developers Club > PI .NET Framework for continued discussion.

          1 of 1 people found this helpful