// constructor
 public Vis_WorkerThread(Vis_Data sharedData, int channelCount)
 {
     this.sharedData   = sharedData;
     this.channelCount = channelCount;
     this.counter      = 0;
     this.queue        = Queue.Synchronized(new Queue());
 }
        public LSL_Visualizer()
        {
            this.FormClosing += visForm_FormClosing;

            this.results = liblsl.resolve_stream("type", "EEG", 1, 5.0);
            if (this.results.Length < 1)
            {
                MessageBox.Show("No gTec Stream Found");
                Environment.Exit(0);
            }
            this.inlet           = new liblsl.StreamInlet(this.results[0]);
            this.channelCount    = this.results[0].channel_count();
            this.sample          = new float[this.channelCount];
            this.chunk           = new float[250, this.channelCount];
            this.visData         = new Vis_Data();
            this.visWorkerThread = new Vis_WorkerThread(this.visData, this.channelCount);
            this.InitializeComponent();
            this.InitializeMainForm();
            this.visData.GtecMainPlot = this.visMainPlot;
            for (int i = 0; i < this.visData.GTEC_SAMPLE_BUFFER_SIZE; i++)
            {
                LineSeries[] visMainSeries = this.visData.visMainSeries;
                for (int j = 0; j < visMainSeries.Length; j++)
                {
                    visMainSeries[j].Points.Add(DataPoint.Undefined);
                }
            }
            for (int k = 0; k < 250; k++)
            {
                for (int l = 0; l < this.channelCount; l++)
                {
                    this.chunk[k, l] = 0f;
                }
            }
            new Thread(new ThreadStart(this.visWorkerThread.Run)).Start();
            this.timer          = new System.Timers.Timer(5.0);
            this.timer.Elapsed += new ElapsedEventHandler(this.UpdateMainPlot);
            this.timer.Start();
        }