NMET
NMET

Reputation: 1

Invoke and System.Windows.Forms.MethodInvoker delegate doesn t work

i have a QRCode scanning project with 2 Forms, form2 opens up after an IF loop in form1, as long as the condition is filled it opens form2 with different data (from different codes) until here everything is right, i want to add a condition that when a new code is scanned and new data is received the already open Form2 is automatically closed before showing the next one

private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)  
{       
    if (Form2 != null && !Form2.IsDisposed && Form2.Visible && Form.ActiveForm == Form2)
    {               
        Form2.Invoke((System.Windows.Forms.MethodInvoker) delegate{ Form2.Close(); });
    }
}      
else
{
    // ...rest of the code
}       

I also tried creating a bool variable and affect the return to it and calling it in an IF loop --> No luck

i also tried creating a public bool and called the void in an if --> No luck

public bool IsStartScannerOpen;

public bool isOpen;

Upvotes: 0

Views: 82

Answers (0)

Related Questions