Home > Net >  C # winform procedure closing has had two threads end. How to end?
C # winform procedure closing has had two threads end. How to end?

Time:03-19

Written in c # a camera detection procedures, inside the Closed method played a breakpoint, close the main window has been Closed method in circulation return not to go out, see not found two threads have been ended, after directly adopt the method of kill thread can quit, but feel this way out there is a problem, to open the software sometimes even not on the camera, is there any way to know the end of the thread what do you use? Just contact with c #, is not very good, hope everybody can help to look at, thank you!

CodePudding user response:

What do you do in form_closed this is closed, Ed is closed, and exit the program, have you no normal disconnect the related equipment, the next time you open, must be equipment occupied, long-term in the past, could eventually to restart your computer, you should use the form_closing or disconnect the power to release, at the time of shut down, you should disconnect the camera connection, of course, if your connection should be global functions, such as disconnectCam (), hope to help you

CodePudding user response:

reference 1st floor wmycom response:
what do you do in form_closed this is closed, Ed is closed, and exit the program, have you no normal disconnect the related equipment, the next time you open, must be occupied equipment, long-term in the past, could eventually to restart your computer, you should use the form_closing or disconnect the power to release, at the time of shut down, you should disconnect the camera connection, of course, if your connection should be global functions, such as disconnectCam (), I hope it can help you

Cameras and sweep code gun which has been disconnected, trying to write the same effect in Closing, break point, too, has been in Closing cycle, couldn't go out, by killing thread can exit, but the method of the way out, to open the software even not on camera, when feeling out of kill threads were used not to let the thread end right, is there any way to know the two threads do you use?

CodePudding user response:

Pay attention to distinguish the foreground thread and a background thread,

https://docs.microsoft.com/zh-cn/dotnet/standard/threading/foreground-and-background-threads

CodePudding user response:

Don't know where you connect the camera method is performed, if it is in the thread inside can follow this

Thread the Thread=new Thread (Thread execution method);
Thread. IsBackground=true;//here is true, said the main thread out of the other threads can also end
Thread. The Start ();


Remember the camera is the need to turn off the camera connection, state, or otherwise occupied on other programs to connect even not, you should have the demo of the camera, looking for a manufacturer of demo to make himself tried
In form_closing set inside the closed condition, such as the camera is turned off and then closing event event set to cancel=false; Should be pulled out of the well

CodePudding user response:

1. Set the two threads to IsBackground=true
2. In the closing when a connection is normally closed camera and sweep code gun using application. The exit

CodePudding user response:

System. The Environment. The Exit (0);
  •  Tags:  
  • C#
  • Related