Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make multi thread for live CAM #11

Closed
giangkieuduc opened this issue Jul 28, 2016 · 1 comment
Closed

How to make multi thread for live CAM #11

giangkieuduc opened this issue Jul 28, 2016 · 1 comment

Comments

@giangkieuduc
Copy link

I have two camera and i want to start CAM1 and CAM2 with two threads
`Thread threadCam1 = new Thread(new ThreadStart(ConnectToCam1));
threadCam1.Start();
Thread threadCam2 = new Thread(new ThreadStart(ConnectToCam2));
threadCam2.Start();
private void ConnectToCam1()
{
try
{

            if (string.IsNullOrEmpty(_cam1Setting.IPCAM))
            {
                         return;
            }

            string cam1URL = "";
            cam1URL = string.Format("rtsp://{0}:{1}@{2}", _cam1Setting.UIDCAM, _cam1Setting.PASSCAM, _cam1Setting.IPCAM);
            uriCAM1 = new Uri(cam1URL);
            liveCAM1.StartPlay(uriCAM1, TimeSpan.FromSeconds(15.0));

        }
        catch 
        {

        }
    }

// ConnectToCam2 is the same
`
but it fired exception Message = "Cross-thread operation not valid: Control 'liveCAM2' accessed from a thread other than the thread it was created on."

How to fix this problem?

Pls help me
Thanks you!

@jacobbo
Copy link
Owner

jacobbo commented Jul 28, 2016

Hi there,

Two options:

  1. Do not use threads.
  2. Access the control from the thread you've created it in. That is a common issue, you can google it.

Regards,
Alexander

On Thu 28 Jul 2016 at 08:56 JKing notifications@github.com wrote:

I have two camera and i want to start CAM1 and CAM2 with two threads
`Thread threadCam1 = new Thread(new ThreadStart(ConnectToCam1));
threadCam1.Start();
Thread threadCam2 = new Thread(new ThreadStart(ConnectToCam2));
threadCam2.Start();
private void ConnectToCam1()
{
try
{

        if (string.IsNullOrEmpty(_cam1Setting.IPCAM))
        {
                     return;
        }

        string cam1URL = "";
        cam1URL = string.Format("rtsp://{0}:{1}@{2}", _cam1Setting.UIDCAM, _cam1Setting.PASSCAM, _cam1Setting.IPCAM);
        uriCAM1 = new Uri(cam1URL);
        liveCAM1.StartPlay(uriCAM1, TimeSpan.FromSeconds(15.0));

    }
    catch
    {

    }
}

// ConnectToCam2 is the same
`
but it fired exception Message = "Cross-thread operation not valid:
Control 'liveCAM2' accessed from a thread other than the thread it was
created on."

How to fix this problem?

Pls help me
Thanks you!


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#11, or mute the thread
https://github.com/notifications/unsubscribe-auth/ABvfwPoPVzyxMuen8blv6YzjfF1uS45yks5qaGCvgaJpZM4JW9GR
.

@jacobbo jacobbo closed this as completed Aug 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants