Pause application
-
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 :)
-
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 :)
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
-
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 :)
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 :)
-
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 :)
Eddy Vluggen wrote:
a call to Application.DoEvents
That way madness lies.
*Developer Day Scotland - Free community conference Delegate Registration Open
-
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 :)
Thank you both for your suggestions, they have come in very handy :)
-
Eddy Vluggen wrote:
a call to Application.DoEvents
That way madness lies.
*Developer Day Scotland - Free community conference Delegate Registration Open
-
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 :)
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 -
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, 2008Normally, 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 :)