/****************************************************/

        internal void SetColor(string color)
        {
            new Thread(() =>
            {
                try
                {
                    //Open the device
                    if (OpenDevice(device))
                    {
                        for (byte i = 0; i < numberOfLeds; i++)
                        {
                            device.SetColor(0, i, color);
                        }

                        // cleanup
                        CloseDevice(device);

                        // save new state
                        currentState       = new BlinkStickState();
                        currentState.State = STATE.SET;
                        currentState.Color = color;
                    }
                }
                catch (Exception)
                {
                }
            }).Start();
        }
        internal void MorphColor(string color, int duration = 125)
        {
            new Thread(() =>
            {
                try
                {
                    //Open the device
                    if (OpenDevice(device))
                    {
                        for (byte i = 0; i < numberOfLeds; i++)
                        {
                            device.Morph(0, i, color, duration / numberOfLeds);
                        }

                        // cleanup
                        CloseDevice(device);

                        // save new state
                        currentState          = new BlinkStickState();
                        currentState.State    = STATE.MORPH;
                        currentState.Color    = color;
                        currentState.Duration = duration;
                    }
                }
                catch (Exception)
                {
                }
            }).Start();
        }
        private void CloseDevice(BlinkStick device)
        {
            lock (lockConcurrentModification)
            {
                lastState = currentState;

                device.CloseDevice();

                isThreadRunning = false;
                cancelThread    = false;
            }
        }
        internal void BlinkColor(string color, int delay = 500, int threadSleep = 100)
        {
            new Thread(() =>
            {
                try
                {
                    //Open the device
                    if (OpenDevice(device))
                    {
                        while (cancelThread == false)
                        {
                            for (byte i = 0; i < numberOfLeds; i++)
                            {
                                device.SetColor(0, i, color);
                            }
                            Thread.Sleep(delay);

                            if (cancelThread)
                            {
                                break;
                            }

                            // turn off
                            for (byte i = 0; i < numberOfLeds; i++)
                            {
                                device.SetColor(0, i, "#000000");
                            }

                            if (cancelThread)
                            {
                                break;
                            }

                            Thread.Sleep(threadSleep);
                        }

                        // cleanup
                        CloseDevice(device);

                        // save new state
                        currentState             = new BlinkStickState();
                        currentState.State       = STATE.PULSE;
                        currentState.Color       = color;
                        currentState.Delay       = delay;
                        currentState.ThreadSleep = threadSleep;
                    }
                }
                catch (Exception)
                {
                }
            }).Start();
        }
        internal void PulseColor(string color, int duration = 1000, int steps = 50, int threadSleep = 100)
        {
            new Thread(() =>
            {
                try
                {
                    Color colorObject;

                    if (color.StartsWith("#"))
                    {
                        colorObject = ColorTranslator.FromHtml(color);
                    }
                    else
                    {
                        colorObject = Color.FromName(color);
                    }

                    byte r = colorObject.R;
                    byte g = colorObject.G;
                    byte b = colorObject.B;

                    //Open the device
                    if (OpenDevice(device))
                    {
                        while (cancelThread == false)
                        {
                            // glow on
                            for (int j = 0; j < steps; j++)
                            {
                                if (cancelThread)
                                {
                                    break;
                                }

                                byte rTemp = (byte)(((float)r) / steps * j);
                                byte gTemp = (byte)(((float)g) / steps * j);
                                byte bTemp = (byte)(((float)b) / steps * j);

                                for (byte i = 0; i < numberOfLeds; i++)
                                {
                                    device.SetColor(0, i, rTemp, gTemp, bTemp);
                                }
                                Thread.Sleep(duration / steps);
                            }

                            // glow off
                            // glow on
                            for (int j = steps - 1; j >= 0; j--)
                            {
                                if (cancelThread)
                                {
                                    break;
                                }

                                byte rTemp = (byte)(((float)r) / steps * j);
                                byte gTemp = (byte)(((float)g) / steps * j);
                                byte bTemp = (byte)(((float)b) / steps * j);

                                for (byte i = 0; i < numberOfLeds; i++)
                                {
                                    device.SetColor(0, i, rTemp, gTemp, bTemp);
                                }
                                Thread.Sleep(duration / steps);
                            }

                            if (cancelThread)
                            {
                                break;
                            }

                            // turn off
                            for (byte i = 0; i < numberOfLeds; i++)
                            {
                                device.SetColor(0, i, "#000000");
                            }

                            if (cancelThread)
                            {
                                break;
                            }

                            Thread.Sleep(threadSleep);
                        }

                        // cleanup
                        CloseDevice(device);

                        // save new state
                        currentState             = new BlinkStickState();
                        currentState.State       = STATE.PULSE;
                        currentState.Color       = color;
                        currentState.Duration    = duration;
                        currentState.Steps       = steps;
                        currentState.ThreadSleep = threadSleep;
                    }
                }
                catch (Exception)
                {
                }
            }).Start();
        }