Home > Net >  Winform video controls stuck when saving
Winform video controls stuck when saving

Time:10-04

Now made a winform interface, the interface has a box, can real-time display images under the camera, code using this website https://www.cnblogs.com/hahaqi/archive/2011/06/02/2068558.html (but this should not focus),
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 interface

CodePudding user response:

refer to the second floor OrdinaryCoder response:
put the recording starts a thread to execute don't directly in the interface thread execution

Sorry, you send the code of the part is part of the real-time display, although this section in the main thread, but there is no problem, this part separate run there is no question of real-time display,
As for the below reply in the place of "recording starts a thread to execute", that's what I do, the recording part is the
 
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
}

This section is written by another thread open ah, opened a thread CamThread
----------------------------------------------

CodePudding user response:

Have not used this component you, do you want to on the commissioned processing, thread will not conflict
  •  Tags:  
  • C#
  • Related