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. Best method for putting a wait

Best method for putting a wait

Scheduled Pinned Locked Moved C#
question
6 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.
  • S Offline
    S Offline
    Subin Mavunkal
    wrote on last edited by
    #1

    Hi , What is the best method for putting a wait in execution.Thread.Sleep() will raise parasoft warnings and its not a good way to use Thread.Sleep every where.Is there any other ways ? Waith warm regards.

    OriginalGriffO B L 3 Replies Last reply
    0
    • S Subin Mavunkal

      Hi , What is the best method for putting a wait in execution.Thread.Sleep() will raise parasoft warnings and its not a good way to use Thread.Sleep every where.Is there any other ways ? Waith warm regards.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Don't. If you pause your application, then your UI will stop responding. Consider instead moving any intensive work to a separate thread, or using a Timer to "wait" for when you should do something. Sleeping thread should only really be used when the thread has nothing to do until the outside world causes a change.

      Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      S 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Don't. If you pause your application, then your UI will stop responding. Consider instead moving any intensive work to a separate thread, or using a Timer to "wait" for when you should do something. Sleeping thread should only really be used when the thread has nothing to do until the outside world causes a change.

        Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

        S Offline
        S Offline
        Subin Mavunkal
        wrote on last edited by
        #3

        If I use AutoResetEvent.WaitOne() , my Static Code Analysis will throw an error for making use of the returning value of WaitOne.Confused!!!!!!!!!!! :(

        OriginalGriffO 1 Reply Last reply
        0
        • S Subin Mavunkal

          If I use AutoResetEvent.WaitOne() , my Static Code Analysis will throw an error for making use of the returning value of WaitOne.Confused!!!!!!!!!!! :(

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          I can understand that. From MSDN:

          Return Value

          Type: System.Boolean
          true if the current instance receives a signal. If the current instance is never signaled, WaitOne never returns.

          Clearly your SCA knows this, and deems it a waste of time checking a result that can never be false! Which of course, it is...

          Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • S Subin Mavunkal

            Hi , What is the best method for putting a wait in execution.Thread.Sleep() will raise parasoft warnings and its not a good way to use Thread.Sleep every where.Is there any other ways ? Waith warm regards.

            B Offline
            B Offline
            BobJanova
            wrote on last edited by
            #5

            You should almost never have an explicit wait. Instead, you should be listening for events which you want to do some action in response to. If you're waiting for another task to complete then you should use WaitHandles, but it's generally better to listen for events.

            1 Reply Last reply
            0
            • S Subin Mavunkal

              Hi , What is the best method for putting a wait in execution.Thread.Sleep() will raise parasoft warnings and its not a good way to use Thread.Sleep every where.Is there any other ways ? Waith warm regards.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Waiting is in general a bad idea, and timing the actions of your software is the way to madness. Can you tell us why you need to wait, or on what specifically? Are you waiting for a signal, such as user-input? Waiting until a process is finished? Waiting until there's data on the socket? If you tell us what you are waiting on, we could perhaps provide an alternative that doesn't involve waiting.

              Bastard Programmer from Hell :suss:

              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