Cross-thread error.
-
OnActivated() MethodInvoker one function to initialize the data of the main form. And before beginInvoke, new the progress form B, the Form B to show the progress to the User. And there is a Timer in the form B, if the time is bigger than 2 seconds, the B Form will showdialog itself to forbide user operation. and then if MethodInvoke function finishs the task, it will stop the form B. then the error shows. "Cross-thread access Form B from the thread is not the thread created by it." the MethodInvoker is the another thread?
-
OnActivated() MethodInvoker one function to initialize the data of the main form. And before beginInvoke, new the progress form B, the Form B to show the progress to the User. And there is a Timer in the form B, if the time is bigger than 2 seconds, the B Form will showdialog itself to forbide user operation. and then if MethodInvoke function finishs the task, it will stop the form B. then the error shows. "Cross-thread access Form B from the thread is not the thread created by it." the MethodInvoker is the another thread?
You can only change or interact with the user interface on the user interface's thread. If you want to change an element of the UI from another thread you have to do something like use the
Invoke
method on theControl
that you wish to manipulate.*Developer Day Scotland - Free community conference Delegate Registration Open
-
You can only change or interact with the user interface on the user interface's thread. If you want to change an element of the UI from another thread you have to do something like use the
Invoke
method on theControl
that you wish to manipulate.*Developer Day Scotland - Free community conference Delegate Registration Open
You mean that: After initialize data, create a method invoke for the Form B stop function to stop FormB. Right? I am to know what will do in the invoke method?
-
You mean that: After initialize data, create a method invoke for the Form B stop function to stop FormB. Right? I am to know what will do in the invoke method?
Look up the
InvokeRequired
property on MSDN or Google. You will find lots of examples there, together with a full explanation of what's going on and why.Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
OnActivated() MethodInvoker one function to initialize the data of the main form. And before beginInvoke, new the progress form B, the Form B to show the progress to the User. And there is a Timer in the form B, if the time is bigger than 2 seconds, the B Form will showdialog itself to forbide user operation. and then if MethodInvoke function finishs the task, it will stop the form B. then the error shows. "Cross-thread access Form B from the thread is not the thread created by it." the MethodInvoker is the another thread?
All timers tick on a separate thread, except for Windows.Forms.Timer :)