I’ve been learning Android lately and I tried to port one of my features to a compact C # environment.
What I did was create an Abstract class, which I call Activity. This class is as follows:
internal abstract class Activity { protected Form myForm; private static Activity myCurrentActivity = null; private static Activity myNextActivity = null; internal static void LoadNext(Activity nextActivity) { myNextActivity = nextActivity; if (myNextActivity != null) { myNextActivity.Show(); if (myCurrentActivity != null) { myCurrentActivity.Close(); myCurrentActivity = null; } myCurrentActivity = myNextActivity; myNextActivity = null; } } internal void Show() {
I have a problem running part of the Show() command
Basically, all my classes implement the above class, download the xml file and display it. When I want to switch to a new class / form (for example, going from ACMain to ACLogIn) I use this code
Activity.LoadNext(new ACLogIn);
It is supposed to load the following form, show it and unload the current form
I tried these solutions (in the Show() method), and here is the problem with each
using myForm.ShowDialog()
This works, but blocks execution, which means the old form does not close, and the more I move between the forms, the more the process stack grows.
using myForm.Show()
This works, closes the old form after showing the old one, but immediately after that closes the program and ends it
using Application.Run(myForm)
This only works in the first form loaded, when I go to the next form, it shows that it throws an exception: "The value is not in the expected range"
Can someone help me fix this or find an alternative?
source share