private void waitForCam(object sender, DoWorkEventArgs e)
        {
            camButtons.initialize(9);

            bool nocam;

            //List<string> camrigCams = new List<string>();
            List<List<string>> camrigCams = new List<List<string>>();

            camrigCams = CameraRig.cameraCredentialsListedUnderProfile(bubble.profileInUse);

            //*****************************
            //IP Webcams
            //*****************************

            //find if any webcams are present
            for (int i = 0; i < camrigCams.Count; i++)
            {

                //we have an ip webcam in the profile
                if (camrigCams[i][1] != string.Empty)
                {

                    IPAddress parsedIPAddress;
                    Uri parsedUri;

                    //check that the url resolves
                    if (Uri.TryCreate(camrigCams[i][1], UriKind.Absolute, out parsedUri) && IPAddress.TryParse(parsedUri.DnsSafeHost, out parsedIPAddress))
                    {

                        Ping pingSender = new Ping();
                        PingReply reply = pingSender.Send(parsedIPAddress);

                        //is ip webcam running?
                        if (reply.Status == IPStatus.Success)
                        {

                            AForge.Video.MJPEGStream stream = new AForge.Video.MJPEGStream(camrigCams[i][1]);

                            if (camrigCams[i][2] != string.Empty)
                            {

                                stream.Login = camrigCams[i][2];
                                stream.Password = camrigCams[i][3];

                            }

                            OpenVideoSource(null, stream, true);

                        }

                    }

                }

            }

            //*****************************
            //IP Webcams
            //*****************************

            //*****************************
            //USB Webcams
            //*****************************

            nocam = false;

            try
            {
                filters = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                if (filters.Count == 0) nocam = true;
            }
            catch (ApplicationException)
            {
                nocam = true;
            }

            //we have camera(s) attached so let's connect it/them
            if (!nocam)
            {

                for (int i = 0; i < filters.Count; i++)
                {

                    for (int c = 0; c < camrigCams.Count; c++)
                    {

                        if (camrigCams[c][1] == string.Empty)
                        {

                            if (filters[i].MonikerString == camrigCams[c][0])
                            {

                                Thread.Sleep(1000);
                                VideoCaptureDevice localSource = new VideoCaptureDevice(camrigCams[c][0]);

                                OpenVideoSource(localSource, null, false);
                                //remove camera from list of cameras to look for as we have now attached it
                                camrigCams.RemoveAt(c);

                            }

                        }

                    }

                }

            }

            //*****************************
            //USB Webcams
            //*****************************
        }
        private void openNewCamera()
        {
            string tmpStr = config.getProfile(bubble.profileInUse).webcam;

            CaptureDeviceForm form = new CaptureDeviceForm(tmpStr, toolTip1.Active);

            if (form.ShowDialog(this) == DialogResult.OK)
            {

                if (form.Device.ipCam)
                {

                    IPAddress parsedIPAddress;
                    Uri parsedUri;

                    //check that the url resolves
                    if (Uri.TryCreate(form.Device.address, UriKind.Absolute, out parsedUri) && IPAddress.TryParse(parsedUri.DnsSafeHost, out parsedIPAddress))
                    {

                        Ping pingSender = new Ping();
                        PingReply reply = pingSender.Send(parsedIPAddress);

                        //the ip webcam is running
                        if (reply.Status == IPStatus.Success)
                        {

                            CameraRig.updateInfo(bubble.profileInUse, form.Device.address, CameraRig.infoEnum.ipWebcamAddress, form.Device.address);

                            AForge.Video.MJPEGStream stream = new AForge.Video.MJPEGStream(form.Device.address);

                            if (form.Device.user != string.Empty)
                            {

                                stream.Login = form.Device.user;
                                stream.Password = form.Device.password;

                                CameraRig.updateInfo(bubble.profileInUse, form.Device.address, CameraRig.infoEnum.ipWebcamUser, form.Device.user);
                                CameraRig.updateInfo(bubble.profileInUse, form.Device.address, CameraRig.infoEnum.ipWebcamPassword, form.Device.password);

                            }

                            OpenVideoSource(null, stream, true);

                        }
                        else
                        {

                            MessageBox.Show("The URL you have entered is not connecting to a webcam." + Environment.NewLine +
                                            "It may be that the webcam has not fully booted yet - it can take 1 minute on some webcams." + Environment.NewLine +
                                            "You may also have supplied an incorrect URL for the webcam.",
                                            "IP Webcam not detected", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);

                        }

                    }
                    else
                    {

                        MessageBox.Show("The URL you have entered is not valid.", "Non Valid URL", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);

                    }

                }
                else
                {

                    if (!CameraRig.camerasAlreadySelected(form.Device.address))
                    {

                        // create video source
                        VideoCaptureDevice localSource = new VideoCaptureDevice(form.Device.address);

                        //config.getProfile(bubble.profileInUse).webcam = form.Device.address;

                        // open camera
                        OpenVideoSource(localSource, null, false);

                    }

                }

            }
        }