1. DnaGetNextHistUTC函数:根据游标一个一个值取
int i = EzDNAApiNet.EzDnaApi.History.DnaGetHistDirectRawUTC(szServer,szPoint, Start, End, ref key);
if (i == 0)
{
long l1 = DateTime.Now.Ticks / 10000;
int s = 0;
int i1 = 0;
while (i1 == 0)
{
i1 = EzDNAApiNet.EzDnaApi.History.DnaGetNextHistUTC(key, ref pdValue, ref ptTime, szStatus, 20);
if (pdValue >= dHighLimit)
{
m_ulHighCount++;
}
if (pdValue<= dLowLimit)
{
m_ulLowCount++;
}
if (i1 == 0)
{
//记住开始时间
if (s == 0)
{
EzDNAApiNet.EzDnaApi.Translator.UCTToStringTime(ptTime, szTime, 30);
sStart = szTime.ToString();
}
s++;
}
}
//记住结束时间
EzDNAApiNet.EzDnaApi.Translator.UCTToStringTime(ptTime, szTime, 30);
sEnd = szTime.ToString();
long l2 = DateTime.Now.Ticks / 10000 - l1;
}
2. DnaGetNextHistBlockSmall函数:一次读取批量数据
int i = EzDNAApiNet.EzDnaApi.History.DnaGetHistDirectRawUTC(szServer,szPoint, Start, End, ref key);
StringBuilder szTime = new StringBuilder(30);
double[] pszValueList = new double[1000000];
int[] pszTimeList = new int[1000000];
ushort[] pszStatusList = new ushort[1000000];
string sStart = "";
string eEnd = "";
if (i == 0)
{
long l1 = DateTime.Now.Ticks / 10000;
int s = 0;
do
{
i1 = EzDNAApiNet.EzDnaApi.History.DnaGetNextHistBlockSmall(key, 1000000, out pnCount, pszValueList, pszTimeList, pszStatusList);
if (0 == i1)
{
for (int j = 0; j < pnCount; j++)
{
//开始时间
if (j == 0)
{
EzDNAApiNet.EzDnaApi.Translator.UCTToStringTime(pszTimeList[j], szTime, 30);
sStart = szTime.ToString();
}
else if (j == pnCount-1)
{
//结束时间
EzDNAApiNet.EzDnaApi.Translator.UCTToStringTime(pszTimeList[j], szTime, 30);
eEnd = szTime.ToString();
}
s++;
}
}
}
while (0 == i1);
long l2 = DateTime.Now.Ticks / 10000 - l1;
方式2比方式1性能有10倍的提高。当然,历史数据查询与磁盘IO性能有很大关系。