mark.omeara

AFAttribute SetValue does not work correctly in a loop

Discussion created by mark.omeara on Feb 6, 2013
Latest reply on Nov 28, 2017 by Rick Davin

 

 

If I am writing values to AF (lets say they are just <none> data reference types, so internal attributes to AF) via the SDK in a loop, I find only some of the values are written, not all. For example

 
for (int i = 0; i < 10000; i++)
{
       MyAttribute.SetValue(new AFValue(i++, new OSIsoft.AF.Time.AFTime(aDateTime)));
     aDateTime = aDateTime.Add(new TimeSpan(1,0,0);
}

The above will not work until a Thread.Sleep is introduced:

 
for (int i = 0; i < 10000; i++)
{
       MyAttribute.SetValue(new AFValue(i++, new OSIsoft.AF.Time.AFTime(aDateTime)));
     aDateTime = aDateTime.Add(new TimeSpan(1,0,0);
     System.Threading.Thread.Sleep(100);
}

 Now all the values are written.... surely I do not need to introduce arbitary sleeps into the code? What is going on?

 

 

Outcomes