我正在使用Geared版 LiveCharts 构建WPF数据可视化工具。
我有一个名为SectionsCollection
的SectionsCollection对象,我需要在数据更改时重新加载。在重新分配到SectionsCollection
之前,我运行以下代码段。
try
{
if (SectionsCollection != null && SectionsCollection.Count > 0)
{
SectionsCollection.Clear();
}
}
catch(Exception e)
{
Status += "Error in clearing SectionsCollection.\n"+e;
}
SectionsCollection = new SectionsCollection();
SectionsCollection.Clear();
行间歇性地发生以下错误,标签 NullReferenceException发生。
Exception thrown: 'System.NullReferenceException' in LiveCharts.Wpf.dll
Additional information: Object reference not set to an instance of an object.
如果我检查SectionsCollection
是否为空并且不为空,为什么会出现此错误?
VisualsCollection和SeriesCollection类型似乎也会出现此错误。
答案 0 :(得分:0)
尝试添加标记以防止不需要的多个exec。在你的过程中:
bool collIsBusy = false;
try
{
if (SectionsCollection != null && SectionsCollection.Count > 0 && !collIsBusy)
{
collIsBusy = true; //flag to prevent throttling multiple executions
SectionsCollection.Clear();
collIsBusy = false;
}
}
catch (Exception e)
{
Status += "Error in clearing SectionsCollection.\n" + e;
}
SectionsCollection = new SectionsCollection();