Siva
Siva

Reputation: 259

Application Process working Background even i close using close() in C#?

i am programming in windows application using c#.

i want to close a application using this.close();

my application windows are closed.but i try to delete that application file,it shows "the file using by an another process"?

note:i am also using backgroundrunner in that application.if it make any problem for the above issue?

Upvotes: 0

Views: 761

Answers (3)

Kareem Khan
Kareem Khan

Reputation: 56

Try calling this function before you exit the main method.

The workerThread is the background worker

public void Abort()
{
    if (workerThread != null)
    {
        workerThread.Abort();
        workerThread = null;
    }
}

Upvotes: 1

Turbot
Turbot

Reputation: 5223

when you use this.Close() , you are closing the window form but not the application.

The background runner you issued in application will still running behind the scene even you explicitly close the form. That's why you are getting the message.

you also might need to check type of background worker if is busy with the processes and handle it gracefully to terminate/complete the request before closing the application. The Application.Exit The foreground threads will continue from terminating, the background will not.

Upvotes: 1

Jay Riggs
Jay Riggs

Reputation: 53593

Try closing your application using Application.Exit.

Informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed.

Upvotes: 1

Related Questions