首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在SectionsCollection中清除LiveCharts中的WPF

在SectionsCollection中清除LiveCharts中的WPF
EN

Stack Overflow用户
提问于 2017-08-09 17:55:30
回答 1查看 2.2K关注 0票数 1

我正在用面向对象的LiveCharts构建一个WPF数据可视化工具。我有一个名为SectionsCollection的SectionsCollection对象,需要在数据变化时重新加载它。在重新分配到SectionsCollection之前,我运行以下代码段。

代码语言:javascript
复制
        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发生

代码语言:javascript
复制
Exception thrown: 'System.NullReferenceException' in LiveCharts.Wpf.dll

Additional information: Object reference not set to an instance of an object.

如果我检查SectionsCollection不是空的,也不是空的,为什么会出现这个错误?

对于VisualsCollection和SeriesCollection类型,似乎也会出现此错误。

EN

回答 1

Stack Overflow用户

发布于 2017-12-12 04:06:02

尝试添加标志以防止不必要的多个exec。在你的过程中:

代码语言:javascript
复制
 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();
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45597594

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档