When do we use Backgroundworker?

ipjyo used Ask the Experts™

My C# application invokes upload process to upload a file.

System.Diagnostics.Process.Start("C:\\Temp\\Upload.cmd", "File1");
I need to delete this file after it gets uploaded. How can I make sure to delete this file only after it is uploaded? Can I use Backgroundworker in this scenario and delete file in the "RunWorkerCompleted" method? Is this a good practice?

Thanks for any suggestions.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Try handling the Exited() event of the Process class:
private void button1_Click(System.Object sender, System.EventArgs e)
    Process P = new Process();
    P.EnableRaisingEvents = true;
    P.Exited += P_Exited;
    P.StartInfo.FileName = @"C:\Temp\Upload.cmd";
    P.StartInfo.Arguments = "File1";

private void P_Exited(object sender, System.EventArgs e)
    // ... delete the file in here ...

Open in new window


Thank you very much. It is working great..

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial