Exemplo n.º 1
0
        private void StartConnection()
        {
            BroadcastProcess.TickRates tickRates = new BroadcastProcess.TickRates
            {
                gps      = 1.0f,
                traffic  = 1.0f,
                attitude = 0.25f
            };
            ThreadStart threadStart = new ThreadStart(() => BroadcastThread(this.context, ProcessStatus, tickRates));

            broadcastThread = new Thread(threadStart);
            broadcastThread.IsBackground = true;
            broadcastThread.Start();
        }
Exemplo n.º 2
0
        private static void BroadcastThread(SynchronizationContext context, ProcessStatusDelegate callback, BroadcastProcess.TickRates tickRates)
        {
            while (true)
            {
                try
                {
                    BroadcastProcess process = new BroadcastProcess(tickRates);
                    while (true)
                    {
                        process.Tick();
                        ProcessStatusData status = new ProcessStatusData
                        {
                            connected = true,
                            error     = false,
                            message   = "Connected."
                        };
                        context.Post(new SendOrPostCallback(callback), status);
                        Thread.Sleep(100);
                    }
                } catch (ThreadAbortException e) {
                    ProcessStatusData status = new ProcessStatusData
                    {
                        connected = false,
                        error     = false,
                        message   = "Broadcast terminated."
                    };
                    context.Post(new SendOrPostCallback(callback), status);
                    return;
                } catch (COMException e) {
                    ProcessStatusData status = new ProcessStatusData
                    {
                        connected = false,
                        error     = true,
                        message   = "Connection to Prepar3d failed."
                    };
                    context.Post(new SendOrPostCallback(callback), status);
                }

                // We'll try to reconnect once a second.
                Thread.Sleep(1000);
            }
        }