troubleshooting Question

System Service And File Delete

Avatar of davism
davismFlag for United States of America asked on
C#Visual Basic.NETMicrosoft Legacy OS
19 Comments2 Solutions527 ViewsLast Modified:
Hi All,

Maybe I'm missing something but I have a system service and I do a File.WriteAllBytes(bla, bla, ...)

Then I want to later, in the service execution, delete that file. The WriteAllBytes creates, opens and closes the file. So, the file should be closed.

Yet when, ater in the service execution, I l try to do a File.Delete(bla) of that temporary file I get an error that it cannot delete the file because it's in use by a process.

The file is a temp file and the only thing using it is the system service.

Am I missing something or is there no way of deleting that file unless the service is stopped and I use the OnStop to delete any and all temporary files?

Any information would be greatly appreciated.

Minh Võ Công

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 19 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 19 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros