Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Closing program...

kern68kern68 Posts: 85Member
I am just about finished with a program that copies files to a network drive. All that's left is handling a few exceptions. One is particularly interesting because it seems so simple. Before copying files I want to ensure that files are closed, so I decided to just close apps that have the file open. A loop checks process names, closes process, waits for process to exit before copying files:
[code]If InStr(proc.ProcessName, FileName.ToUpper) Then
proc.CloseMainWindow()
Debug.Write("process found")
proc.WaitForExit()
Exit For

blah.blah.copyfile("c:lahlah.file", "y:lah.file", TRUE)[/code]

The WaitForExit() does not seem to wait long enough because I still get exceptions if this program closes the application. Everything runs fine if the apps are closed before running this program.

How can I safely stop an app before copying files?

Another, less major, issue is when a large file is copying and another window is dragged in front of the form, the border of the active window appears to smear across the form. I tried to Refresh() when the form signaled a paint event, but that stuck in the paint event loop. How can I refresh the form in a case like this?

Thanks for the help,
GeoK
[italic]Blah,[/italic][b]Blah,[/b][b][italic]Blah[/italic]!![/b]

Comments

  • zibadianzibadian Posts: 6,349Member
    : I am just about finished with a program that copies files to a
    : network drive. All that's left is handling a few exceptions. One
    : is particularly interesting because it seems so simple. Before
    : copying files I want to ensure that files are closed, so I decided
    : to just close apps that have the file open. A loop checks process
    : names, closes process, waits for process to exit before copying
    : files:
    : [code]: If InStr(proc.ProcessName, FileName.ToUpper) Then
    : proc.CloseMainWindow()
    : Debug.Write("process found")
    : proc.WaitForExit()
    : Exit For
    :
    : blah.blah.copyfile("c:lahlah.file", "y:lah.file", TRUE)[/code]:
    :
    : The WaitForExit() does not seem to wait long enough because I still
    : get exceptions if this program closes the application. Everything
    : runs fine if the apps are closed before running this program.
    :
    : How can I safely stop an app before copying files?
    :
    : Another, less major, issue is when a large file is copying and
    : another window is dragged in front of the form, the border of the
    : active window appears to smear across the form. I tried to
    : Refresh() when the form signaled a paint event, but that stuck in
    : the paint event loop. How can I refresh the form in a case like
    : this?
    :
    : Thanks for the help,
    : GeoK
    : [italic]Blah,[/italic][b]Blah,[/b][b][italic]Blah[/italic]!![/b]

    You should do your copying in another thread, so that the main thread remains responsive to the messages of windows.
Sign In or Register to comment.