简体   繁体   中英

C# WinForms Wait on form to proceed

I'm tired and hungry, so I might of missed it, but from what I can see no existing post covers this...

I'm writing a plugin for an application. My plugin loads a form to get some data specifically, it uses the webcam to scan for a barcode. Once it's found a barcode, the form hides itself (incase it's needed again later). This is how I currently call the form that does the barcode work:

string readData = null;

if (eye == null)
{
    System.Windows.Forms.Application.EnableVisualStyles();
    eye = new CamView();
}
eye.Show();
if (eye.found)
{
    readData = eye.readData;
}

return readData;

So, my problem is that eye.show() doesn't block. It makes the form appear and carries right on before there's a chance for the barcode to appear. I imagine I need to use some form of threading or locking, but my crude attempts to do so have just frozen the interface completely.

The "eye" form is basically just a viewfinder for the webcam, and relies on the camera_OnImageCapture event to make it do it's image checks for the barcode.

Is there an elegant way to make the application calling the plugin wait for the form to finish? Or do I just need to add an accept button to the "eye form?"

Cheers. And humble apologies if this is in anyway a repost.

.ShowDialog(); http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx

"You can use this method to display a modal dialog box in your application. When this method is called, the code following it is not executed until after the dialog box is closed. "

You are on the right track. You change the code to show CamView as a modal dialog but do no add an Accept button. Instead change camera_OnImageCapture to close the dialog.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM