I am working on a console application that creates a form to notify users of any given state - at a later stage, the code base will become a class library.
Currently, however, I need to show the form (ShowDialog will be the best method here, I think) THEN call an arbitrary method before closing the form.
As an example, I need to show the form, set the text value of the label control, wait n seconds, then change the label value, and then close the form. I know this sounds a little trivial, but I'm trying to prove the concept of design.
I looked around and it doesn't seem like it is possible since ShowDialog () requires me to close the form before I can continue by listing the code in the calling method / class.
Here is what I still have:
PopUpForm myForm = new PopUpForm(string messageToDisplay); myForm.ShowDialog(); //call myForm.someMethod() here, before the form closes //dispose of the form, now that we've no use for it myform.Dispose(); //target method in PopUpform class public void someMethod() { lblText.Text = "Waiting for some reason"; //wait n number of seconds lblText.Text = "Finished waiting. Form will now close"; //it doesn't matter if the form closes before the user can see this. }
It appears that ShowDialog () does not support this behavior. I look at BackgroundWorker topics, but wondered if anyone has any advice on this or whether this has occurred before.
source share