Link to home
Start Free TrialLog in
Avatar of JackW9653
JackW9653Flag for United States of America

asked on

Trapping for IO Exception

Hello Experts,

I have a pocket pc app that moves files to a specific folder on the network for batch printing. After the files are printed they get renamed and moved to another folder. The possibility exists the another user may try to print the same file by moving it to the print folder before the process can rename it. The files are set to read-only after printing and before the move. If that happens I get the standard message of "an unhandled exception of type IO.IOExceptions has occured in mscorlib". Is there anyway to trap for that and pause the execution of the IO.Move for a specified amount of time - say 15 seconds?

Thanks,

Jack
ASKER CERTIFIED SOLUTION
Avatar of omegaomega
omegaomega
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JackW9653

ASKER

Hello Omega,

Yes this is what I am looking for but there are a couple issues with your routine. What namespace is thread.sleep need? I had to comment it out to get it to compile. And after success I have to hit cancel to exit the loop. But we are close.

Thanks for your help.
System.Threading.Thread.Sleep()

Bob
Omega, imported System.Threading and the sleep function worked, but still need to exit the loop when the file is copied successfully. Thanks.
In order to exit the loop, you need to set booSuccess = True.

Bob
Where in the code above would that go?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Bob, I removed that line and tweaked a couple of other things and it worked.

Jack
Hello, Bob,

Many thanks for your all your assistance to the OP with this.  I was away from my bench all day.  

As you guessed, my code was intended only as an example.  The "Throw" line was there because I needed to generate an I/O error for the example, and didn't want to bother with setting up some real I/O that would fail.  

Cheers.
Randy