Во время переподключения к квику вылетает ошибка


Во время переподключения к квику вылетает ошибка
Atom
24.03.2013


Когда переподключается коннектор возникает сообщение об ошибке что колонки таблиц уже добавлены
и действительно при первом подключении добавляются дополнительные колонки :
_trader.SecuritiesTable.Columns.Add(DdeSecurityColumns.BestAskPrice);
_trader.SecuritiesTable.Columns.Add(DdeSecurityColumns.BestBidPrice);

Как сделать так что-бы не вылетало это
Вся процедура подключения ниже в коде.
Заранее благодарен

Код
        {

            var guiListener = new GuiLogListener();

            _logManager.Listeners.Add(guiListener);


            if (_trader == null && terminals.cbTerminals.Text != "")
            {

                _trader = new QuikTrader(terminals.cbTerminals.Text) { SupportManualOrders = true };
                _trader.ReConnectionSettings.ExportTimeOutInterval = TimeSpan.FromSeconds(10);
                
                _trader.ReConnectionSettings.WorkingTime = _trader.ReConnectionSettings.WorkingTime = Exchange.Rts.WorkingTime; //.Test.WorkingTime;//

                _trader.ReConnectionSettings.ConnectionRestored += () => this.GuiAsync(() => 
                    {
                        //MessageBox.Show(this, "Соединение восстановлено");
                        connect_disconect("connected");
                        start_copy();
                    }
                    );
                _trader.ReConnectionSettings.IsReStartExport = true;
                _trader.ConnectionError += error => this.GuiAsync(() => MessageBox.Show(this, error.ToString()));

                //_trader.Disconnected += new Action(_trader_Disconnected);

                Q_path = terminals.cbTerminals.Text;

                _trader.Connected += () =>
                {

                    try
                    {

                        _trader.SecuritiesTable.Columns.Add(DdeSecurityColumns.BestAskPrice);
                        _trader.SecuritiesTable.Columns.Add(DdeSecurityColumns.BestBidPrice);

                        //lbConn.Content = "1";

                        _trader.StartExport();

                        if (SelectedPortfolio != null && SelectedSecurity != null)//SelectedPortfolio
                        {
                            var myposition = _trader.GetPosition(SelectedPortfolio, SelectedSecurity).CurrentValue;
                           
                            this.GuiAsync(() =>
                            {
                                lbCPose2.Content = myposition;
                                
                            });

                        }

                    }//try
                    catch (Exception ee)
                    {

                        MessageBox.Show("Произошла ошибка связи и Квиком 1 " + ee.ToString());

                    }

                };

                

                
                _trader.NewSecurities += securities => this.GuiAsync(() =>
                {
                    try
                    {
                        cbSecuritites.ItemsSource = _trader.Securities;
                        cbSecuritites.SelectedIndex = 0;
                       
                    }//try
                    catch (Exception ee)
                    {
                        MessageBox.Show("Произошла ошибка связи и Квиком 2 " + ee.ToString());
                       

                        connect_disconect("0");

                    }

                });


                _trader.SecuritiesChanged += security => this.GuiAsync(() =>
                {
                    try
                    {
                        if (_trader != null)
                        {
                            cbSecuritites.ItemsSource = _trader.Securities;

                            if (SelectedSecurity != null)
                            {

                                label2.Content = SelectedSecurity.BestBid.Price.ToString();
                                lbBestAsk.Content = SelectedSecurity.BestAsk.Price.ToString();
                            }
                        }
                    }//try
                    catch (Exception ee)
                    {

                        if (_trader != null)
                        {
                            MessageBox.Show("Произошла ошибка связи и Квиком 2.1 " + ee.ToString());

                            connect_disconect("0");

                        }
                    }

                });

                _trader.NewPortfolios += portfolios => this.GuiAsync(() =>
                {
                    try
                    {
                        Portfolios.ItemsSource = _trader.Portfolios; //cbSecuritites.ItemsSource = _trader.Securities;//  _trader.StartExport();
                        Portfolios.SelectedIndex = 1;
                        if (SelectedPortfolio != null)// && SelectedSecurity != null)//SelectedPortfolio SelectedSecurity);//
                        {
                            //  _trader.RegisterMarketDepth(SelectedSecurity);
                        }
                        //lbConnected.Content = "Connected";
                        connect_disconect("connected");
                        tbVolume.Text = "1";
                        //tbDelta.Text = "0";
                        btConnect.Background = default_but_color;
                        // Connect_.Background = default();//    System.Windows.Media.LinearGradientBrush;// Brushes.LightPink;
                        // register_MDs();
                    }//try
                    catch (Exception ee)
                    {
                        MessageBox.Show("Произошла ошибка связи и Квиком 3 " + ee.ToString());
                    }

                });


                _trader.PositionsChanged += positions => this.GuiAsync(() =>
                {
                    //конркетная позиция по конкретному портфелю инструменту
                    if (SelectedPortfolio != null && SelectedSecurity != null)//SelectedPortfolio
                    {
                        var myposition = positions.FirstOrDefault(p => p.Portfolio == SelectedPortfolio && p.Security == SelectedSecurity);//SelectedPortfolio
                        if (myposition != null)
                        {
                            lbCPose2.Content = myposition.CurrentValue;
                            //on_change_pose();
                        }

                    }

                });

                try
                {
                    _trader.Connect();
                }//try
                catch (Exception ee)
                {
                    MessageBox.Show("Произошла ошибка связи и Квиком 5" + ee.ToString());
                    // return;
                }

                _trader.ConnectionError += errror => this.GuiAsync(() =>
                {
                    if (_trader != null)
                    {
                       // _trader.Dispose();
                        connect_disconect("0");
                        //_trader = null;
                        //clear_all();
                    }
                });

            }
            else
            {
                if (_trader != null && _trader.IsConnected)
                {
                   // if (_trader != null)  _trader.Dispose();
                    connect_disconect("0");
                   // _trader = null;
                    clear_all();
                }
            }
           

        }



Спасибо:




Добавить файлы через драг-н-дроп, , или вставить из буфера обмена.

loading
clippy