Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Cross-thread error.

Cross-thread error.

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fired Fish Gmail
    wrote on last edited by
    #1

    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?

    C L 2 Replies Last reply
    0
    • F Fired Fish Gmail

      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?

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      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 the Control that you wish to manipulate.

      *Developer Day Scotland - Free community conference Delegate Registration Open

      F 1 Reply Last reply
      0
      • C Colin Angus Mackay

        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 the Control that you wish to manipulate.

        *Developer Day Scotland - Free community conference Delegate Registration Open

        F Offline
        F Offline
        Fired Fish Gmail
        wrote on last edited by
        #3

        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?

        H 1 Reply Last reply
        0
        • F Fired Fish Gmail

          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?

          H Offline
          H Offline
          Henry Minute
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • F Fired Fish Gmail

            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?

            L Offline
            L Offline
            Luc 648011
            wrote on last edited by
            #5

            All timers tick on a separate thread, except for Windows.Forms.Timer :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups