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. Visual Basic
  4. Pause application

Pause application

Scheduled Pinned Locked Moved Visual Basic
helpquestion
8 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.
  • J Offline
    J Offline
    Jay Royall
    wrote on last edited by
    #1

    Hi, In my application I am trying to export a Crystal Report to a PDF and then use that PDF. But the problem I have is that the export doesn't complete quick enough for my application to use it. Any ideas on the best way to pause my application unitl the export is complete? Thanks :)

    C L J 3 Replies Last reply
    0
    • J Jay Royall

      Hi, In my application I am trying to export a Crystal Report to a PDF and then use that PDF. But the problem I have is that the export doesn't complete quick enough for my application to use it. Any ideas on the best way to pause my application unitl the export is complete? Thanks :)

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

      Liqz wrote:

      Any ideas on the best way to pause my application unitl the export is complete?

      I take it you are trying to open the PDF but failing because it is still being written to? What you could do is loop around attempting to open the file. When you manage to open the file you know it is ready. Until then you just loop around again. Also, be aware that this could potentially introduce an infinite loop in your application if the file handle is never released by Crystal Reports so you will want to build in a time out mechanism so that after attempting for a period of time you give up.

      *Developer Day Scotland - Free community conference Delegate Registration Open

      1 Reply Last reply
      0
      • J Jay Royall

        Hi, In my application I am trying to export a Crystal Report to a PDF and then use that PDF. But the problem I have is that the export doesn't complete quick enough for my application to use it. Any ideas on the best way to pause my application unitl the export is complete? Thanks :)

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

        You can 'halt' the current thread, stopping execution of your code (5 seconds in the example below)

        System.Threading.Thread.CurrentThread.Sleep(5000)

        This will prevent the form from drawing, because your application isn't processing messages. An alternative method would be to put the current time in a variable and enter a loop with a call to Application.DoEvents. Break the loop if a specified amount of time hath expired. Third possibility is the use of the timer-component :) Happy Programming!

        I are troll :)

        C D 2 Replies Last reply
        0
        • L Lost User

          You can 'halt' the current thread, stopping execution of your code (5 seconds in the example below)

          System.Threading.Thread.CurrentThread.Sleep(5000)

          This will prevent the form from drawing, because your application isn't processing messages. An alternative method would be to put the current time in a variable and enter a loop with a call to Application.DoEvents. Break the loop if a specified amount of time hath expired. Third possibility is the use of the timer-component :) Happy Programming!

          I are troll :)

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

          Eddy Vluggen wrote:

          a call to Application.DoEvents

          That way madness lies.

          *Developer Day Scotland - Free community conference Delegate Registration Open

          L 1 Reply Last reply
          0
          • J Jay Royall

            Hi, In my application I am trying to export a Crystal Report to a PDF and then use that PDF. But the problem I have is that the export doesn't complete quick enough for my application to use it. Any ideas on the best way to pause my application unitl the export is complete? Thanks :)

            J Offline
            J Offline
            Jay Royall
            wrote on last edited by
            #5

            Thank you both for your suggestions, they have come in very handy :)

            1 Reply Last reply
            0
            • C Colin Angus Mackay

              Eddy Vluggen wrote:

              a call to Application.DoEvents

              That way madness lies.

              *Developer Day Scotland - Free community conference Delegate Registration Open

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

              Don't be afraid, and embrace that madness - you don't want to be the last sane person here, do you? Insanity doth tickle the imagination :-D

              I are troll :)

              1 Reply Last reply
              0
              • L Lost User

                You can 'halt' the current thread, stopping execution of your code (5 seconds in the example below)

                System.Threading.Thread.CurrentThread.Sleep(5000)

                This will prevent the form from drawing, because your application isn't processing messages. An alternative method would be to put the current time in a variable and enter a loop with a call to Application.DoEvents. Break the loop if a specified amount of time hath expired. Third possibility is the use of the timer-component :) Happy Programming!

                I are troll :)

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                Bad solution. Your code assumes that the operation will, forever, take under 5 seconds to complete. A better solution would be to try and open the file with DenyShareAll sharing permissions every so often, say 500 milliseconds, until the file opens. Then you'll know the file is finished writing, no matter how long it takes.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008

                L 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  Bad solution. Your code assumes that the operation will, forever, take under 5 seconds to complete. A better solution would be to try and open the file with DenyShareAll sharing permissions every so often, say 500 milliseconds, until the file opens. Then you'll know the file is finished writing, no matter how long it takes.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007, 2008

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

                  Normally, I'd reply that any working solution isn't bad, but this is a dirty hack and not a solution. The thing is that you notice that 5 seconds isn't always enough, so you extend the period to 10 seconds. That's kinda cool when the task usually finishes within half a second, leaving you to wait for 9,5 seconds every dang time. How often do you come across a place where the application is waiting, no disk-activity and no cpu-activity? My train of thought departed from the application. What do you do when you can't change the code to send a message to signal an event? It didn't even cross my mind that one could check the object that the application is working on, I just kept thinking on the same track - where the problem arises. In short, thanks for showing a better option than the quick-and-dirty 'solution' :)

                  I are troll :)

                  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