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 operation not valid

Cross thread operation not valid

Scheduled Pinned Locked Moved C#
visual-studiohelpquestion
8 Posts 6 Posters 1 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.
  • S Offline
    S Offline
    satsumatable
    wrote on last edited by
    #1

    Hi I did code to access my control(text box etc) inside the thread but when i upgrade it into VS 2005 it is saying "cross thread operation not valid" how can fix it ? - Thanks

    S B H V 4 Replies Last reply
    0
    • S satsumatable

      Hi I did code to access my control(text box etc) inside the thread but when i upgrade it into VS 2005 it is saying "cross thread operation not valid" how can fix it ? - Thanks

      S Offline
      S Offline
      sunil2004
      wrote on last edited by
      #2

      Dear Siva, Is that is happening in debugh mode or it happens in release build also? I also face the same problem while debugging the application :( but it works fine in release build. Regards, Sunil Tonger

      1 Reply Last reply
      0
      • S satsumatable

        Hi I did code to access my control(text box etc) inside the thread but when i upgrade it into VS 2005 it is saying "cross thread operation not valid" how can fix it ? - Thanks

        B Offline
        B Offline
        blackjack2150
        wrote on last edited by
        #3

        Control.CheckForIllegalCrossThreadCalls = false; Put this line in the constructor of your form.

        L S 2 Replies Last reply
        0
        • B blackjack2150

          Control.CheckForIllegalCrossThreadCalls = false; Put this line in the constructor of your form.

          L Offline
          L Offline
          lmoelleb
          wrote on last edited by
          #4

          Yes, when you are doing something referred to as "Illigal" then obvious choice is to disable the check so you can get on with your high quality code. X| Look at Invoke and BeginInvoke. Yes, they are annoying, but not half as annoying as the deadlocks you get when not using them.

          1 Reply Last reply
          0
          • B blackjack2150

            Control.CheckForIllegalCrossThreadCalls = false; Put this line in the constructor of your form.

            S Offline
            S Offline
            satsumatable
            wrote on last edited by
            #5

            Control.CheckForIllegalCrossThreadCalls = false; will this cause any issues? I have code in 2003 which access controls inside thread and so far it is going good. I placed this command in 2005 and tried it already and it looks OK, i want to make sure by making this "CheckForIllegalCrossThreadCalls" as false will not cause any serious issues. Do you think? http://www.codeproject.com/csharp/threadsafeforms.asp[^] this should be the right choice but lot of rework :)

            L 1 Reply Last reply
            0
            • S satsumatable

              Hi I did code to access my control(text box etc) inside the thread but when i upgrade it into VS 2005 it is saying "cross thread operation not valid" how can fix it ? - Thanks

              H Offline
              H Offline
              Hessam Jalali
              wrote on last edited by
              #6

              just use delegate for invoking them Here is my code and it's work fine in vs2005

              public delegate void CrossThreadHandle(object arg);

                  void SetLabelStatus(object txt)
                  {
                      this.labelDownloadStatus.Text=txt as string;
                  }
              
              
                  void dl\_StatusChanged(Downloader sender, Downloader.DownloadStatus status)
                  {
                     CrossThreadHandle dLabel=new CrossThreadHandle(this.SetLabelStatus);
                      this.Invoke(dLabel,sender.Status.ToString());
              
                      Application.DoEvents();
                  }
              

              Hope it would Help

              1 Reply Last reply
              0
              • S satsumatable

                Control.CheckForIllegalCrossThreadCalls = false; will this cause any issues? I have code in 2003 which access controls inside thread and so far it is going good. I placed this command in 2005 and tried it already and it looks OK, i want to make sure by making this "CheckForIllegalCrossThreadCalls" as false will not cause any serious issues. Do you think? http://www.codeproject.com/csharp/threadsafeforms.asp[^] this should be the right choice but lot of rework :)

                L Offline
                L Offline
                lmoelleb
                wrote on last edited by
                #7

                Of course setting the option to false will cause issues. Microsoft did not add a random unneeded check just for the fun of it. Typical behaviour will be random hanging your entire GUI. This can happen on all systems, or just a few. It can also appear to be working fine, then suddently start hanging due to an update from Microsoft, a new OS, or whatever.

                1 Reply Last reply
                0
                • S satsumatable

                  Hi I did code to access my control(text box etc) inside the thread but when i upgrade it into VS 2005 it is saying "cross thread operation not valid" how can fix it ? - Thanks

                  V Offline
                  V Offline
                  Vasudevan Deepak Kumar
                  wrote on last edited by
                  #8

                  http://www.codeproject.com/useritems/AccessControlFromThread.asp[^]

                  Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                  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