M. Nasir Javaid
M. Nasir Javaid

Reputation: 5990

Main thread showing a form as dialog, how to close it programmatically by using worker thread?

I want to close a form showing as dialog by main thread. I am using beginInvoke to show that dialog and want to close or hide when worker thread complete its own task.

Upvotes: 0

Views: 884

Answers (2)

Moha Dehghan
Moha Dehghan

Reputation: 18443

Same as showing the form, for closing the form you can also use BeginInvoke() or Invoke().

form.Invoke(new Action(form.Close));

or if the code is inside the form itself, replace the form with this.

Upvotes: 1

Grrbrr404
Grrbrr404

Reputation: 1805

If you are using the BackgroundWorker, there is a event available: "OnRunWorkerCompleted" - It triggers if the worker has completed.

You can use this event to close your form.

Upvotes: 2

Related Questions