Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 336701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:16:02+00:00 2026-05-12T10:16:02+00:00

I do the following: Copy an executable to C:\temp\x.exe Start the executable with System.Diagnostics.Process.Start

  • 0

I do the following:

  1. Copy an executable to C:\temp\x.exe

  2. Start the executable with System.Diagnostics.Process.Start and then wait for the process to exit, synchronously, by calling WaitForExit on the Process object returned by Start.

  3. Delete the executable C:\temp\x.exe

On some machines, this works great, but on others, the call to DeleteFile fails, because the file is still in use. So it seems that once WaitForExit returns, it does not imply that Windows is done with the EXE.

What are my options here? The obvious one whould be to try again the DeleteFile a few milliseconds later, in a loop, until deletion succeeds or the loop times out. But is there a cleaner way to wait for a file to be closed by everyone?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:16:02+00:00Added an answer on May 12, 2026 at 10:16 am

    There’s a few reasons way your exe could still be locked when it’s done executing. some have to do with your code and some with the system. The two main reasons I can think off for your code would be:

    How you close the filestream when you copy the exe file to the temp location, if it’s not released explicitly the release timing might change from time to time.

    the second is even though the process is done executing doesn’t mean it’s done in a system perspective.

    The first one can be avoid the second can be monitored in the process list BUT you still have a bag of possible locks (your program executing twice in parallel, virus scan some one manually cleaning the temp folder, disc cleanup wizard). So I’d suggest either to rework the logic of the program. If the executeable is written in c# load the binary and execute the program instead of copying the file.

    If you for some reason needs to copy the file every time it’s executed spawn a low priority cleanup thread. let it try to clean up after the WaitForExit call if that fails make it try again after x milliseconds if that fails again try after 2x and so forth.

    That being said I guess their would be (probably unmanaged) API calls to look for file locks on a system level. Personally I would just have the system it self figure that out though

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 204k
  • Answers 204k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Check out `highlight-regexp'. Just type in the word you want… May 12, 2026 at 8:43 pm
  • Editorial Team
    Editorial Team added an answer If you step through the macros (Use F8) you should… May 12, 2026 at 8:43 pm
  • Editorial Team
    Editorial Team added an answer You want the 'single precision store' pseudoinstruction. I think this… May 12, 2026 at 8:43 pm

Related Questions

I've written an application in Microsoft Visual C# 2008 Express Edition. The Windows XP
Using NetBeans, I do the following in the class containing main() , and it
I can't seem to find a more efficient way to copy an embedded resource
If for example I create an array of pixels, like so: int *getPixels() {

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.