Stuart P
Stuart P

Reputation: 79

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.

Upvotes: 1

Views: 1727

Answers (2)

Richard Schneider
Richard Schneider

Reputation: 35477

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.

Upvotes: 2

Kristoffer Schroeder
Kristoffer Schroeder

Reputation: 688

.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."

Upvotes: 3

Related Questions