AFChangeInfo.FindObject Method (PISystem, Boolean)
- Last UpdatedJan 12, 2026
- 4 minute read
- PI System
- AF SDK 3.2.0
- Developer
Finds the object represented by change information structure and optionally
automatically load from the server if not found.
Namespace: OSIsoft.AF
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.2.0.7
Syntax
public AFObject FindObject( PISystem system, bool autoLoad )
Public Function FindObject ( system As PISystem, autoLoad As Boolean ) As AFObject Dim instance As AFChangeInfo Dim system As PISystem Dim autoLoad As Boolean Dim returnValue As AFObject returnValue = instance.FindObject(system, autoLoad)
public: AFObject^ FindObject( PISystem^ system, bool autoLoad )
member FindObject : system : PISystem * autoLoad : bool -> AFObject
Parameters
- system
- Type: OSIsoft.AFPISystem
The PISystem to be used when searching for the object. - autoLoad
- Type: SystemBoolean
If and the object is not already loaded, it will be loaded from the server. If and it not already loaded, then will be returned.
Return Value
Type: AFObjectReturns the object represented by the change information structure. If not found, then is returned.
Remarks
If the object was already loaded in the SDK, it will be updated by calling
Refresh. If it was not already loaded and
autoLoad is , it will
be loaded from the server with the latest updates.
Examples
// This example demonstrates getting changes made by other users // and refreshing the objects. // Get the System and System Cookie PISystem myPISystem = new PISystems().DefaultPISystem; object sysCookie = myPISystem.GetFindChangedItemsCookie(searchSandbox: false); // Wait for changes to be made... //======================================================= // Find changes made by other users. List<AFChangeInfo> list = new List<AFChangeInfo>(); int resultsPerPage = 1000; while (true) { var results = myPISystem.FindChangedItems(false, true, resultsPerPage, sysCookie, out sysCookie); if ((results?.Count ?? 0) == 0) break; list.AddRange(results); } // Refresh objects that have been changed. AFChangeInfo.Refresh(myPISystem, list); // Find the objects that have been changed. foreach (AFChangeInfo info in list) { AFObject myObj = info.FindObject(myPISystem, false); Console.WriteLine("Found changed object: {0}", myObj); }
// This example demonstrates persisting and restoring the cookie // using the XmlSerializer. Other serializers could also be used. // Then the cookie is restored and used to get changes made while // the application was shut down. // Get the System and Database and their Cookie Values PISystem myPISystem = new PISystems().DefaultPISystem; AFDatabase myDB = myPISystem.Databases.DefaultDatabase; object sysCookie = myPISystem.GetFindChangedItemsCookie(searchSandbox: false); object dbCookie; myDB.FindChangedItems(false, int.MaxValue, null, out dbCookie); // Persist the cookie if you want to save to pick up changes // where you left off after restarting application. string tmpDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); string sysCookieFile = Path.Combine(tmpDir, "AFSysCookie.xml"); string dbCookieFile = Path.Combine(tmpDir, "AFDbCookie.xml"); XmlSerializer serializer = new XmlSerializer(typeof(object[])); using (var stream = File.Create(sysCookieFile)) { serializer.Serialize(stream, sysCookie); } using (var stream = File.Create(dbCookieFile)) { serializer.Serialize(stream, dbCookie); } // Shut down application, and wait for changes to be made... //======================================================= // After application restarts, reload persisted cookies. using (var stream = File.OpenRead(sysCookieFile)) { sysCookie = serializer.Deserialize(stream); } using (var stream = File.OpenRead(dbCookieFile)) { dbCookie = serializer.Deserialize(stream); } // Find changes made while application not running. List<AFChangeInfo> list = new List<AFChangeInfo>(); int resultsPerPage = 1000; while (true) { var results = myPISystem.FindChangedItems(false, resultsPerPage, sysCookie, out sysCookie); if ((results?.Count ?? 0) == 0) break; list.AddRange(results); } while (true) { var results = myDB.FindChangedItems(false, resultsPerPage, dbCookie, out dbCookie); if ((results?.Count ?? 0) == 0) break; list.AddRange(results); } // Find the objects that have been changed. foreach (AFChangeInfo info in list) { AFObject myObj = info.FindObject(myPISystem, false); Console.WriteLine("Found changed object: {0}", myObj); }