Cancel Closing Form in Form Closing event
-
Hi, Is it possible to cancel Form Colosing in the Form Closing Event ? I have background worker in my form and when user try to close a form where a background worker is still busy, I want to let the user know that, "A background process is still busy, Try closing Later" -- And then Return the method without closing the form.
-
Hi, Is it possible to cancel Form Colosing in the Form Closing Event ? I have background worker in my form and when user try to close a form where a background worker is still busy, I want to let the user know that, "A background process is still busy, Try closing Later" -- And then Return the method without closing the form.
The onclose event has a CancelEventArgs prameter e. set e.Cancel to true.
-
The onclose event has a CancelEventArgs prameter e. set e.Cancel to true.
Thanks wheelerbarry, As far I know, these onClose, onLoad type events are protected members and I will have to override this methods right ? Is not it possible simply using e.Cancel within FormClosing event handler ?
-
Thanks wheelerbarry, As far I know, these onClose, onLoad type events are protected members and I will have to override this methods right ? Is not it possible simply using e.Cancel within FormClosing event handler ?
Hello
bashiwala wrote:
Is not it possible simply using e.Cancel within FormClosing event handler ?
Yes it is! It's even the standard practice. Yet better make it the other way around. You shouldn't make the user wait for the thread. The thread should wait the user. Make your background worker a Background thread that will b terminated once the application is closed so that the use won't get frustrated waiting for something they don't even see or know when will it finish.
Regards:rose:
-
Hello
bashiwala wrote:
Is not it possible simply using e.Cancel within FormClosing event handler ?
Yes it is! It's even the standard practice. Yet better make it the other way around. You shouldn't make the user wait for the thread. The thread should wait the user. Make your background worker a Background thread that will b terminated once the application is closed so that the use won't get frustrated waiting for something they don't even see or know when will it finish.
Regards:rose:
What happens when I execute Application.Exit() if a background worker is still busy in that application ? I assume that, all threads and background workers are immediately stopped and the application isexited. Is not that right ? The same question is for Application's main parent form closing. If the user simply click the cross button of top right corner of the Main Parent Window to close, will the threads and background workers are terminated immediately or they keep on running invisible ?
-
What happens when I execute Application.Exit() if a background worker is still busy in that application ? I assume that, all threads and background workers are immediately stopped and the application isexited. Is not that right ? The same question is for Application's main parent form closing. If the user simply click the cross button of top right corner of the Main Parent Window to close, will the threads and background workers are terminated immediately or they keep on running invisible ?
You'd be surprised if I tell you that i've never used those BackgroundWorkers!! I always use good old fashioned multithreading. I even don't know why they made this clas?!! Anyway, if a thread is made Foreground then it will keep running invisible and your applicatoin won't really exit. You can check that out using the task manager. But if you make that thread background by setting Thread.IsBackground = true, then it will close once all foreground threads are close and the process won't wait for that thread to finish. I don't know about BackgroundWorker class if it's really background, but it would take a small test to find out -I'm currently too lazy to lookup MSDN;P-
Regards:rose:
-
You'd be surprised if I tell you that i've never used those BackgroundWorkers!! I always use good old fashioned multithreading. I even don't know why they made this clas?!! Anyway, if a thread is made Foreground then it will keep running invisible and your applicatoin won't really exit. You can check that out using the task manager. But if you make that thread background by setting Thread.IsBackground = true, then it will close once all foreground threads are close and the process won't wait for that thread to finish. I don't know about BackgroundWorker class if it's really background, but it would take a small test to find out -I'm currently too lazy to lookup MSDN;P-
Regards:rose:
Thanks :) I feel more comfortable using Google than MSDN to search for a C# solution.