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. timer and threading?

timer and threading?

Scheduled Pinned Locked Moved C#
questiondebugginghelp
9 Posts 3 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.
  • M Offline
    M Offline
    Mir_As
    wrote on last edited by
    #1

    i start my timer than when timer is elapsed i want to change my sliderbars value in private void timer1_elapsed(object sender, System.Timers.ElapsedEventArgs e) { slider1.value=100; //i get error message in this line about threading and debug s broken.how can i solve it? }

    L G 2 Replies Last reply
    0
    • M Mir_As

      i start my timer than when timer is elapsed i want to change my sliderbars value in private void timer1_elapsed(object sender, System.Timers.ElapsedEventArgs e) { slider1.value=100; //i get error message in this line about threading and debug s broken.how can i solve it? }

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, you must be more specific: - what kind of timer, there are at least three different Timer classes in CLR - what Exception My best guess is you are NOT using a Forms.Timer hence your timer is accessing a Control from within a thread that did not create said Control, hence resulting in an InvalidOperationException. If this suits your case, read up on Control.InvokeRequired and Control.Invoke() :)

      Luc Pattyn try { [Search CodeProject Articles] [Search CodeProject Forums] [Forum Guidelines] [My Articles] } catch { [Google] }

      M 1 Reply Last reply
      0
      • M Mir_As

        i start my timer than when timer is elapsed i want to change my sliderbars value in private void timer1_elapsed(object sender, System.Timers.ElapsedEventArgs e) { slider1.value=100; //i get error message in this line about threading and debug s broken.how can i solve it? }

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        If your timer is running in a thread that doesn't own slider then you need to call Invoke methods. Have a look at this: http://msdn.microsoft.com/msdnmag/issues/04/02/TimersinNET/

        #region signature my articles #endregion

        M 1 Reply Last reply
        0
        • L Luc Pattyn

          Hi, you must be more specific: - what kind of timer, there are at least three different Timer classes in CLR - what Exception My best guess is you are NOT using a Forms.Timer hence your timer is accessing a Control from within a thread that did not create said Control, hence resulting in an InvalidOperationException. If this suits your case, read up on Control.InvokeRequired and Control.Invoke() :)

          Luc Pattyn try { [Search CodeProject Articles] [Search CodeProject Forums] [Forum Guidelines] [My Articles] } catch { [Google] }

          M Offline
          M Offline
          Mir_As
          wrote on last edited by
          #4

          i get this message when i try to set sliderbar s value.System.InvalidOperationException.i used "using System.window.threading; " i think i must break timer s threading than slider bar s valur could be changed.

          L 1 Reply Last reply
          0
          • G Giorgi Dalakishvili

            If your timer is running in a thread that doesn't own slider then you need to call Invoke methods. Have a look at this: http://msdn.microsoft.com/msdnmag/issues/04/02/TimersinNET/

            #region signature my articles #endregion

            M Offline
            M Offline
            Mir_As
            wrote on last edited by
            #5

            i get this message when i try to set sliderbar s value.System.InvalidOperationException.i used "using System.window.threading; " i think i must break timer s threading than slider bar s valur could be changed.

            1 Reply Last reply
            0
            • M Mir_As

              i get this message when i try to set sliderbar s value.System.InvalidOperationException.i used "using System.window.threading; " i think i must break timer s threading than slider bar s valur could be changed.

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              So you have confirmed my assumption. You must: either switch to a Forms.Timer or call myControl.Invoke() instead of directly trying to change the Control (read up on Invoke !). :)

              Luc Pattyn try { [Search CodeProject Articles] [Search CodeProject Forums] [Forum Guidelines] [My Articles] } catch { [Google] }

              M 1 Reply Last reply
              0
              • L Luc Pattyn

                So you have confirmed my assumption. You must: either switch to a Forms.Timer or call myControl.Invoke() instead of directly trying to change the Control (read up on Invoke !). :)

                Luc Pattyn try { [Search CodeProject Articles] [Search CodeProject Forums] [Forum Guidelines] [My Articles] } catch { [Google] }

                M Offline
                M Offline
                Mir_As
                wrote on last edited by
                #7

                please can you write code?i tried to write but i couldnt do it.

                L 1 Reply Last reply
                0
                • M Mir_As

                  please can you write code?i tried to write but i couldnt do it.

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  Hi, I'm not going to do your work. Did you try a Forms.Timer ? if not, why not ? Did you read the MSDN documentation on your current timer ? and Forms.Timer ? Did you try to call Invoke ? if so, show the code, and explain what happened. If not, why not ? Did you at least search CodeProject for InvokeRequired/Invoke ? and read an article about them ? :)

                  Luc Pattyn try { [Search CodeProject Articles] [Search CodeProject Forums] [Forum Guidelines] [My Articles] } catch { [Google] }

                  M 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    Hi, I'm not going to do your work. Did you try a Forms.Timer ? if not, why not ? Did you read the MSDN documentation on your current timer ? and Forms.Timer ? Did you try to call Invoke ? if so, show the code, and explain what happened. If not, why not ? Did you at least search CodeProject for InvokeRequired/Invoke ? and read an article about them ? :)

                    Luc Pattyn try { [Search CodeProject Articles] [Search CodeProject Forums] [Forum Guidelines] [My Articles] } catch { [Google] }

                    M Offline
                    M Offline
                    Mir_As
                    wrote on last edited by
                    #9

                    ok i have done it now.thanks all of so much good night

                    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