C
C#2y ago
Lander

❔ Winforms one window app with navigation between windows

Hello there, I'm trying to implement a one window winforms app with navigation between the various forms using a dictionary and abit of manipulation with Dispose and Application.Run() Here is a snippet of the running loop code
while (navigatedForm != "quitting")
{
switch (navigatedForm)
{
case "LoginForm":
allForms[navigatedForm] = new LoginForm();
break;
case "RegisterForm":
allForms[navigatedForm] = new RegisterForm();
break;
//case "EmailVerificationForm":
// allForms[navigatedForm] = new EmailVerificationForm();
// break;
case "MainMenuForm":
allForms[navigatedForm] = new MainMenuForm();
break;


default:
break;
}

try
{
Application.Run(allForms[navigatedForm]);
}
catch (Exception ex)
{

DisplayTestWindow(ex.Message, ex.Source, 1);

}
Application.Exit();

}
while (navigatedForm != "quitting")
{
switch (navigatedForm)
{
case "LoginForm":
allForms[navigatedForm] = new LoginForm();
break;
case "RegisterForm":
allForms[navigatedForm] = new RegisterForm();
break;
//case "EmailVerificationForm":
// allForms[navigatedForm] = new EmailVerificationForm();
// break;
case "MainMenuForm":
allForms[navigatedForm] = new MainMenuForm();
break;


default:
break;
}

try
{
Application.Run(allForms[navigatedForm]);
}
catch (Exception ex)
{

DisplayTestWindow(ex.Message, ex.Source, 1);

}
Application.Exit();

}
In each form when the user goes to the next, I call Dispose(). In terms of memory, when I tested going back and forth on 2 forms, the Task Manager shown that the memory didn't significantly bypassed the 30-50 MB threshold and at one point dropped to the starting 18 MB. My question is, Is this way hacky and unsafe or it's fine?
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server