views:

112

answers:

2

I use a login from to access the main application. There is a logout option from the main application, which i'm not able to implement, even after googling and trying some things like:

Application.Restart();

or

Application.OpenForms["loginForm"].ShowDialog();
mainForm.Close();

Help needed to implement a simple logout option. There's an exception thrown, smth like:

InvalidOperationException: Collection was modified; enumeration operation may not execute.

Thnx in advance.

A: 

What I would do is to hide the main window and display the login form. After the new login just check if the main form exists and show it with the new data (for the new user) or just close it and open a new one.

Another solution would be maybe to have a controller method that displays the forms. For example have a loop that displays the login form, then the main form. When the main form is closed the login form will be displayed again.

rslite
something like a while loop in the main method?
trinity
and where\when should the main form be closed?
trinity
Yes, something like that and the main form will be closed when the user logs out
rslite
A: 

Regarding When the form should be closed is upon opening the Login form, after selecting Logout. When the User signs in, it should send the username and pass to the main form, where it can be verified, and then load the specific data pertaining to that user...

Michael