Now want to do is click a button, can real-time display, while videos (click on the automatic real-time display), then there is an avi file, function has been implemented well, general idea is: to create a thread in the click function, the video function binding on the thread, then start the thread, the following code
Private void collectStart_Click (object sender, EventArgs e)
{
CamThread=new Thread (CamReadFun);
CamThread. Start ();
}
Private void CamReadFun ()
{
Video. StarKinescope (Path.Com bine (newpath, DateTime. Now. The ToString (" yyyy - MM - dd (HH. MM. Ss) ") + ". Avi "));
//this function is the function in the above web page, the parameters for the save path
}
But the problem comes, when I click on the button, the mouse will become a load of the state, if I want to click on the button, the window will become not response status,
At this time as long as the other casually open a not maximize window (for example, a browser), then the window will return to normal, and the recording will automatically stop,
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Doubt is now broadcast and recording in different threads at the same time take up video resources, lead to stuck, so try the asynchronous, but didn't also effect, the code is as follows:
The delegate void StarKinescopeInvoker (string path);
Private void CamReadFun ()//video
{
StarKinescopeInvoker Invoker=new StarKinescopeInvoker (video. StarKinescope);
Bine Invoker. The BeginInvoke (Path.Com (newpath, DateTime. Now. The ToString (" yyyy - MM - dd (HH. MM. Ss) ") + ". Avi "), null, null);
}
By the way, the image display is used the two lines of code:
Video=new cVideo (picCapture. Handle, 640, 480);//picCapture PictureBox variables of type, used to display
Status_cam=video. StartWebCam ();//if the connection is successful will probably be true
If you don't perform StartWebCam function can't recording, so also can't separate to record to experiment,
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
If there are bosses know how to solve appreciate ORZ
CodePudding user response:
Private void the Save ()
{
Task. Run (()=& gt;
{
Status_cam=video. StartWebCam ();//if the connection is successful will probably be true
});
}
CodePudding user response:
Put the recording starts a thread to execute the thread execution don't directly in the interfaceCodePudding user response: