BUG_overflowException with AppendAsync method

Apr 14, 2009 at 10:59 PM

I am working with the version posted on a precedent discussion under Windows Vista:

In the following code, I simply added a chartPlotter (called "plotter") to a window and a button to start the simulation.
If you start debugging, a StackOverFlowException will appear ("An unhandled exception of type 'System.StackOverflowException' occurred in WindowsBase.dll") .

Please, try it!

Now, if you think that the overflow exception appears because of this line of code : "Thread.Sleep(1)", try this:
  • Replace "Thread.Sleep(1)" by "Thread.Sleep(100)"
  • Put a breakpoint in the debug mode at the following line "_source.AppendAsync(Dispatcher, NewTrade);"
  • Start the debug and you are going to see the stackOverflow beginning in the call Stack of VS 2008. But here is the strange thing. If you don't see the stackOverflow beginning, stop the debug mode and start it a second time. If you still don't see it, stop and start a third time. And so on, and you are going the see the bug before the fifth try!!!
Now, Replace "Thread.Sleep(100)" by "Thread.Sleep(1000)" and you will never see the bug again...

This kind of bug didn't exist in the first release of ddd.

Please, can anyone help me on this?

I am using ddd for financial application on tick data (each transaction). Since a lot of transaction could appear in a second I still can not use my application to trade into the market.

Thanks a lot,

XAML code:

<Window x:Class="ddd_overflow.Window1"
    Title="Window1" Height="300" Width="300">
        <my:ChartPlotter Margin="12,24,12,41" Name="plotter" />
        <Button Height="19" Margin="93,0,88,11" Name="button1" VerticalAlignment="Bottom" Click="button1_Click">Button</Button>

C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
using Microsoft.Research.DynamicDataDisplay;
using Microsoft.Research.DynamicDataDisplay.DataSources;

namespace ddd_overflow
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
        private ObservableDataSource<Trade> _source;
        private Random _rand;

        public Window1()
            _rand = new Random();

        void EditPlotter()
            _source = new ObservableDataSource<Trade>();
            _source.SetXMapping(x => x.Counter);
            _source.SetYMapping(y => y.Price);
                    new Pen(Brushes.Gold, 3),
                    new PenDescription("Sin(x + phase)"));

        void AddNewTrade(Trade NewTrade)
                      ///////// Put a breakpoint at the following line! //////////////

                       _source.AppendAsync(Dispatcher, NewTrade);


                   catch (Exception ex)


        private void button1_Click(object sender, RoutedEventArgs e)
            Thread thread = new Thread(BeginSimulation);

        void BeginSimulation()
            int counter = 0;
            for (int i = 0; i < 1000000; i++)
                Trade trade = new Trade();
                trade.Counter = counter;
                trade.Price = _rand.NextDouble();



        public class Trade
            public double Counter { get; set; }
            public double Price { get; set; }

Apr 15, 2009 at 1:40 PM

Market opening this morning, the application frozed right away! Lol...

The StackOverflowException doesn't come from the fact there are too much data but when when the data are updated too fast.

I am stuck, any help would be greatly appreciated :)

Apr 16, 2009 at 9:25 AM
Hi, Kamel!

I've reproduced bug you've described.

You can change your method AddNewTrade method, removing calling of Dispatcher.BeginInvoke(...), so that the complete body of this method will look like this:
void AddNewTrade(Trade NewTrade)


            _source.AppendAsync(Dispatcher, NewTrade);


This stops StackOverflowException from appearing.

Also I can advice you to set property IsBackground to true at thread you are creating. This is not connected to DynamicDataDisplay but this will allow application to close when you close main window (when thread you are creating is not background, it will exist after main thread exiting and application will live forever even when you've closed main window).


Mikhail Brinchuk,

DynamicDataDisplay Dev Team.

Apr 16, 2009 at 12:04 PM
As easy as deleting some code?
I love it!

Thanks, it works great!  :)