Simple problem with events...  
Author Message
jaomello





PostPosted: Visual C# Language, Simple problem with events... Top

Hi !
I opened a form and did this:

private void bt_envia_Click(object sender, EventArgs e)
        {
globais.portaSerial.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(portaSerial_DataReceived);
}
delegate void delAtualiza(string texto);
void portaSerial_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
textBox3.Invoke(new delAtualiza(atualiza), new Object[] { globais.portaSerial.ReadChar().ToString() });
}
private void atualiza(string texto)
{
textBox3.Text += texto + "#";
}

Ok.. al things is right... but and a close the form and open again, it happens:
Error:
"Invoke or BeginInvoke cannot be called on a control until the window handle has been created."
at this line: textBox3.Invoke(new delAtualiza(atualiza), new Object[] { globais.portaSerial.ReadChar().ToString() });

Well, i think it happens because a need finish "all operations" in my form... am i correct if i'm correct, how If not... what i need to do

(If i explain bad...because i not speak English... i try speak in another way...)

Hug,
Joao Mello


Visual C#17  
 
 
Figo Fei - MSFT





PostPosted: Visual C# Language, Simple problem with events... Top

Hi, Joao Mello
This kind of error has been discussed in another two threads:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=85847&SiteID=1

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=322154&SiteID=1

Hope you can find the answer.

Hug.