1

私はDynamicDataDisplayプロットに慣れています。エラー メッセージが表示されました:デバッガーが次の行にヒットしたときに別のスレッドがそれを所有しているため、呼び出し元のスレッドはこのオブジェクトにアクセスできません:

Action AddLineGraph = delegate()
{    
    timeDomainPlotter.AddLineGraph(_ods,
        new Pen(_curveColors[_statsEnableIndex[i]], 2),
        new CirclePointMarker { Size = 5, Fill = _curveColors[_statsEnableIndex[i]] },
        new PenDescription(Convert.ToString(j)));
};

this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, AddLineGraph);

次のように使用してプロットを描画するとき、私はこれについて混乱してLineGraphいます:

Action AddLineGraph = delegate()
{
    timeDomainPlotter.AddLineGraph(_ods, 2, "Ch" + Convert.ToString(j) + _statsName[_statsEnableIndex[i]]);
};

this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, AddLineGraph);

それはうまくいきます。ポイントマーカーを描画するとエラーメッセージが表示されるのはなぜですか?ありがとう。

_curveColors編集:が定義されている場所に追加したコーディングを次に示します。

public void InitiatePlot()
{
//  InitializeComponent();

    //   timeDomainPlotter.Legend.Remove();

    _initialChildrenCount = timeDomainPlotter.Children.Count;

    int count = timeDomainPlotter.Children.Count;

    //do not remove the initial children
    if (count > _initialChildrenCount)
    {
        for (int i = count - 1; i >= _initialChildrenCount; i--)
        {
            timeDomainPlotter.Children.RemoveAt(i);
        }
    }


//  _curveColors = new System.Drawing.Color[_nMaxStatsPerChannel];
    _curveColors = new Brush[_nMaxStatsPerChannel];


    for (int i = 0; i < _nMaxStatsPerChannel; i++)
    {

        _curveColors[i] = new SolidColorBrush((Color)ColorConverter.ConvertFromString(_colorList[i]));
    // _curveColors[i] = System.Drawing.Color.FromName(_colorList[i]);

    }

    _statsName = Enum.GetNames(typeof(Window1.ROISignalList));


    //_statsEnableIndex = new int[_nActiveStatsPerChannel];
    for (int j = 0; j < _nActiveChannels; j++)  // init data source structure
    {
    // count = 0;
        for (int i = 0; i < _nActiveStatsPerChannel; i++)
        {

            _ods = new ObservableDataSource<Point>();
            _odsAll[j * _nActiveStatsPerChannel + i] = _ods;   // _osdAll: C0S0 C0S1 C0S2 C1S0 C1S1 C1S2 ... C4S0 C4S1 C4S2


            Action AddLineGraph = delegate()
        {

            timeDomainPlotter.AddLineGraph(_ods,
                    new Pen(_curveColors[_statsEnableIndex[i]], 2),
                    new CirclePointMarker { Size = 5, Fill = _curveColors[_statsEnableIndex[i]] },
                    new PenDescription(Convert.ToString(j)));
        };
        this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, AddLineGraph);

        }
    }
}

理由がわかりました。SpaceghostAli が言及したのとまったく同じように、_curveColors が実際にこのエラーの原因です。

理由が完全にはわからなかったと言わざるを得ませんが、すべての _curveColors を定義済みの色に置き換えると、問題はなくなります。特に、エラーが発生するコードは次のとおりです。

Action AddLineGraph = delegate()
{

    timeDomainPlotter.AddLineGraph(_ods,
        new Pen(_curveColors[_statsEnableIndex[i]], 2),
        new CirclePointMarker { Size = 5, Fill = _curveColors[_statsEnableIndex[i]] },
        new PenDescription(Convert.ToString(j)));
};

this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, AddLineGraph);

エラーのないコードは次のとおりです。

Action AddLineGraph = delegate()
{

    timeDomainPlotter.AddLineGraph(_ods,
        //new Pen(_curveColors[_statsEnableIndex[i]], 2),
        new Pen( new SolidColorBrush(Colors.Transparent), 2),
        new CirclePointMarker { Size = 5, Fill = new SolidColorBrush(Colors.Green) },
        new PenDescription(Convert.ToString(j)));
};

this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, AddLineGraph);

_curveColors のみが確定的な色に変更されていることがわかります。

4

1 に答える 1

2

UIスレッドで_curveColorsが作成されていないと思います。トレース バックして InitiatePlot がどのように呼び出されているかを確認し、UI スレッドが _curveColors を所有していることを確認する必要があります。

于 2013-03-11T16:20:06.297 に答える