Esempio n. 1
0
 public void ReadAndProcessMessages()
 {
     try
     {
         while (!stopEvent.WaitOne(0))
         {
             int incomingMessage = ReadInt();
             ProcessIncomingMessage(incomingMessage);
         }
     }
     catch (IOException)
     {
     }
     catch (Exception e)
     {
         // For when TWS is closed when the trading program open
         if (parent.IsConnected())
         {
             parent.Wrapper.error(e);
         }
     }
     if (parent.IsConnected())
     {
         tcpReader.Close();
         parent.Close();
     }
 }
        public void Start()
        {
            new Thread(() =>
            {
                try
                {
                    while (eClientSocket.IsConnected())
                    {
                        if (!eClientSocket.IsDataAvailable())
                        {
                            Thread.Sleep(1);
                            continue;
                        }

                        if (!putMessageToQueue())
                        {
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    eClientSocket.Wrapper.error(ex);
                    eClientSocket.eDisconnect();
                }

                eReaderSignal.issueSignal();
            })
            {
                IsBackground = true
            }.Start();
        }
Esempio n. 3
0
        public void Start()
        {
            new Thread(() =>
            {
                try
                {
                    while (eClientSocket.IsConnected())
                    {
                        if (!putMessageToQueue())
                        {
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    // 1. System.IO.IOException is expected when main thread exits and after it calls ClientSocket.eDisconnect();
                    // in the msg processing loop this throws the exception: IbApiSocketClient.dll!IBApi.EClient.ReadInt()
                    // Fine. It seems we cannot prevent it. We cannot cancel this putMessageToQueue() loop.
                    // It is written that once it is started, it always listen. No way to cancel it.

                    // 2. System.IO.EndOfStreamException happens when a previous disconnection went wrong and IbGateway still hangs-on the connection, not realizing it was disconnected.
                    // Succesive connections have problems. Solution: restart the IbGateway/TWS that is stuck on that open connection.

                    eClientSocket.Wrapper.error(ex);
                    eClientSocket.eDisconnect();
                }

                eReaderSignal.issueSignal();
            })
            {
                IsBackground = true
            }.Start();
        }
Esempio n. 4
0
 public void Start()
 {
     if (MessageQueueThread?.Status == TaskStatus.Running)
     {
         throw new Exception(new { MessageQueueThread = new { MessageQueueThread.Status } } +"");
     }
     MessageQueueThread = Task.Factory.StartNew(() => {
         while (eClientSocket.IsConnected())
         {
             if (!putMessageToQueue())
             {
                 break;
             }
         }
     }, TaskCreationOptions.LongRunning);
     MessageQueueThread.ContinueWith(_ => eReaderSignal.issueSignal());
 }
Esempio n. 5
0
        public void Start()
        {
            new Thread(() =>
            {
                while (eClientSocket.IsConnected())
                {
                    if (!putMessageToQueue())
                    {
                        break;
                    }
                }

                eReaderSignal.issueSignal();
            })
            {
                IsBackground = true
            }.Start();
        }
Esempio n. 6
0
        public void Start()
        {
            new Thread(() =>
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

                while (eClientSocket.IsConnected())
                {
                    if (!putMessageToQueue())
                    {
                        break;
                    }
                }

                eReaderSignal.issueSignal();
            })
            {
                IsBackground = true
            }.Start();
        }