![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | "InvalidOperationException" when closing a form (using VS2008) Good Afternoon, This problem has been plaguing me most of the afternoon. I have an application that interfaces with an external device and reports status. There is a requirement that the application be able to save outgoing messages with unique names so when the TCP client sends a message, I created an event that the main application responds to. In the body of that event, I create an instance of my formand display it for the user. The user can choose to ignore this particular message by pressing the "Discard" button or keep it by pressing the "Keep" button. If the user presses the "Discard" button, I just want to close the form. When I call this.Close() I get an InvalidOperationException which I understand to mean that the form is trying to close on a thread that did not create it. How do I get this to work? I am familiar with accessing controls correctly using delegates but I can't seem to get this to work properly. Would I have to raise an event back to the main application so it can close the form? If so, do I have to create the new form in it's own thread? Thanks! Jonathan |
My System Specs![]() |
| | #2 (permalink) |
| | Re: "InvalidOperationException" when closing a form (using VS2008) Try this: BeginInvoke( new Action(Close) ) Josh "Jonathan Jones" <JonathanJones@xxxxxx> wrote in message news 3A127AB-B74B-48C5-8BD6-316FA8F5C6FC@xxxxxxQuote: > Good Afternoon, > > This problem has been plaguing me most of the afternoon. I have an > application that interfaces with an external device and reports status. > There is a requirement that the application be able to save outgoing > messages > with unique names so when the TCP client sends a message, I created an > event > that the main application responds to. In the body of that event, I > create > an instance of my formand display it for the user. The user can choose to > ignore this particular message by pressing the "Discard" button or keep it > by > pressing the "Keep" button. > > If the user presses the "Discard" button, I just want to close the form. > When I call > > this.Close() > > I get an InvalidOperationException which I understand to mean that the > form > is trying to close on a thread that did not create it. How do I get this > to > work? I am familiar with accessing controls correctly using delegates but > I > can't seem to get this to work properly. > > Would I have to raise an event back to the main application so it can > close > the form? If so, do I have to create the new form in it's own thread? > > Thanks! > > Jonathan |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Most games closing, the message says it has "stopped working" | Gaming | |||
| "...must be placed inside a form tag with runat=server" error | .NET General | |||
| (Vista 64-bit) Can one somehow "dump" a program's memory (e.g., firefox or chrome) to a file and load after closing a program? | Vista file management | |||
| Not responding when closing "Local Area Connection Properties" box | Vista networking & sharing | |||
| "Reclaim space on closing" Error | Live Mail | |||