modal dialog and Application.run

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I want to ask for a user before running the application, and be able to restart the application if the user wants to change the "user"

In my main methode I have something like this (pseudocode)

static void main()

//My user dialoo
MyUserDialog mud = new MyUserDialog(

do

if(mud.ShowDialog == DialogResult.OK)
Application.Run(new...)

}while(myapp.Reenter == true); // myApp is a static in my application

mud.Dispose()


Basically it fails on restart becase the modal dialogs close automatically, but the first time it works properly. When I comment the "Application.Run(new ...)" line, the modal dialog works properly, asking again and again for the user, but with this line uncommented it fails

Thanks in advance.
 
Try to re-create the dialog every time the execution flow enters the loop
and dispose of the dialog after the Application.Run method exits.

Not a performance-friendly solution though :-(

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Cosh said:
Hi,

I want to ask for a user before running the application, and be able to
restart the application if the user wants to change the "user".
In my main methode I have something like this (pseudocode):

static void main(){

//My user dialoog
MyUserDialog mud = new MyUserDialog()

do{

if(mud.ShowDialog == DialogResult.OK){
Application.Run(new...);
}
}while(myapp.Reenter == true); // myApp is a static in my application.

mud.Dispose();
}

Basically it fails on restart becase the modal dialogs close
automatically, but the first time it works properly. When I comment the
"Application.Run(new ...)" line, the modal dialog works properly, asking
again and again for the user, but with this line uncommented it fails.
 
Thanks Dmitriy

I have already try this, and the result is exactly the same, the form apears and disapears very fast with the cancel result.

Regards
 
if(mud.ShowDialog == DialogResult.OK){
Application.Run(new...);

When Application.Run() returns, the application has already been told to
quit. It may remember this state and close any new popups.

Try not to call Application.Run(), but to use MainForm.Show() instead?

Greetings,
Wessel
 
Back
Top