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. Other Discussions
  3. The Weird and The Wonderful
  4. Stopwatch To pause App ????

Stopwatch To pause App ????

Scheduled Pinned Locked Moved The Weird and The Wonderful
helpquestion
7 Posts 7 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.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    Just found this:

    private void App_Exit(object sender, ExitEventArgs e)
    {
    ConnectionManager.IConnectionManager.Shutdown() // Disconnect from device
    // Wait for 4 sec to check if Connection Manager is shutdown. Else close anyway.
    Stopwatch sw = new Stopwatch();
    sw.Start();
    while (sw.Elapsed < TimeSpan.FromMilliseconds(4000))
    {
    // Wait
    }
    sw.Stop();
    }

    Guess the dev didn't know about

    System.Threading.Thread.Sleep(4000);

    If it's not broken, fix it until it is

    L B P G 4 Replies Last reply
    0
    • K Kevin Marois

      Just found this:

      private void App_Exit(object sender, ExitEventArgs e)
      {
      ConnectionManager.IConnectionManager.Shutdown() // Disconnect from device
      // Wait for 4 sec to check if Connection Manager is shutdown. Else close anyway.
      Stopwatch sw = new Stopwatch();
      sw.Start();
      while (sw.Elapsed < TimeSpan.FromMilliseconds(4000))
      {
      // Wait
      }
      sw.Stop();
      }

      Guess the dev didn't know about

      System.Threading.Thread.Sleep(4000);

      If it's not broken, fix it until it is

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

      But with "Sleep" you get no Attention the Task Manager :-D ...

      1 Reply Last reply
      0
      • K Kevin Marois

        Just found this:

        private void App_Exit(object sender, ExitEventArgs e)
        {
        ConnectionManager.IConnectionManager.Shutdown() // Disconnect from device
        // Wait for 4 sec to check if Connection Manager is shutdown. Else close anyway.
        Stopwatch sw = new Stopwatch();
        sw.Start();
        while (sw.Elapsed < TimeSpan.FromMilliseconds(4000))
        {
        // Wait
        }
        sw.Stop();
        }

        Guess the dev didn't know about

        System.Threading.Thread.Sleep(4000);

        If it's not broken, fix it until it is

        B Offline
        B Offline
        Brisingr Aerowing
        wrote on last edited by
        #3

        :doh: :laugh:

        What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???

        1 Reply Last reply
        0
        • K Kevin Marois

          Just found this:

          private void App_Exit(object sender, ExitEventArgs e)
          {
          ConnectionManager.IConnectionManager.Shutdown() // Disconnect from device
          // Wait for 4 sec to check if Connection Manager is shutdown. Else close anyway.
          Stopwatch sw = new Stopwatch();
          sw.Start();
          while (sw.Elapsed < TimeSpan.FromMilliseconds(4000))
          {
          // Wait
          }
          sw.Stop();
          }

          Guess the dev didn't know about

          System.Threading.Thread.Sleep(4000);

          If it's not broken, fix it until it is

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Shouldn't burden of waiting for the disconnect to happen be placed on the Shutdown method? At most the caller should specify the timeout: ConnectionManager.IConnectionManager.Shutdown(4000)

          1 Reply Last reply
          0
          • K Kevin Marois

            Just found this:

            private void App_Exit(object sender, ExitEventArgs e)
            {
            ConnectionManager.IConnectionManager.Shutdown() // Disconnect from device
            // Wait for 4 sec to check if Connection Manager is shutdown. Else close anyway.
            Stopwatch sw = new Stopwatch();
            sw.Start();
            while (sw.Elapsed < TimeSpan.FromMilliseconds(4000))
            {
            // Wait
            }
            sw.Stop();
            }

            Guess the dev didn't know about

            System.Threading.Thread.Sleep(4000);

            If it's not broken, fix it until it is

            G Offline
            G Offline
            glen205
            wrote on last edited by
            #5

            I found almost this exact code in the splashscreen of an app I inherited responsibility for.... "The app takes too long to start" was the complaint from the customer. In fact the splashscreen sat there burning up CPU cycles as fast as possible performing "sw.Elapsed.TotalMilliseconds < 10000". Then once the 10 seconds had elapsed it closed the splashscreen and *then* started all the application init tasks (DB connection, load config etc...) I replaced the stopwatch with: - a background thread to perform the app init (which normally took about 7 seconds) - a thead.sleep to "pad" the splashscreen's lifespan up to 10 seconds Apparently a 10-second splashscreen was desired, but cramming the app init into that 10 seconds cured the customer's "slow app" nicely.

            P 1 Reply Last reply
            0
            • G glen205

              I found almost this exact code in the splashscreen of an app I inherited responsibility for.... "The app takes too long to start" was the complaint from the customer. In fact the splashscreen sat there burning up CPU cycles as fast as possible performing "sw.Elapsed.TotalMilliseconds < 10000". Then once the 10 seconds had elapsed it closed the splashscreen and *then* started all the application init tasks (DB connection, load config etc...) I replaced the stopwatch with: - a background thread to perform the app init (which normally took about 7 seconds) - a thead.sleep to "pad" the splashscreen's lifespan up to 10 seconds Apparently a 10-second splashscreen was desired, but cramming the app init into that 10 seconds cured the customer's "slow app" nicely.

              P Offline
              P Offline
              Peter_in_2780
              wrote on last edited by
              #6

              I always thought the purpose of the splashscreen was to distract the user from how long the app took to get initialised. Back in the day when I did such things, my strategy was for the mainline of the app to throw out a splashscreen, do the grunt work of initialisation then kill the splashscreen. Cheers, Peter

              Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

              N 1 Reply Last reply
              0
              • P Peter_in_2780

                I always thought the purpose of the splashscreen was to distract the user from how long the app took to get initialised. Back in the day when I did such things, my strategy was for the mainline of the app to throw out a splashscreen, do the grunt work of initialisation then kill the splashscreen. Cheers, Peter

                Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

                N Offline
                N Offline
                Nathan Minier
                wrote on last edited by
                #7

                Intent and reality intersect far too rarely.

                "There are three kinds of lies: lies, damned lies and statistics." - Benjamin Disraeli

                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