Link to home
Start Free TrialLog in
Avatar of mastiSoft
mastiSoft

asked on

Problem with closing window.

Hi, I need to know how to force close one window from another in WPF.
I have one window,splash screen with do some background work. When it finish do all it have to it have to disappear and new window have to opens.
I use following code to do that:

MainWindow main = new MainWindow();

main.Show();
this.Close();

Open in new window


It works always on PC on tablet it works only one time after program was installed or tablet restarted,
Second time main window shows with splash screen over it.  Because the splash screen give to some global variables values that make possible to run Main form
I suspect the this splash screen not closed when application close. I close the application from main window:

Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
Application.Current.Shutdown();

Open in new window


It is very difficult to debug because the problem is visible only on tablet not on PC.
Because of that I think I have to force closing of Splash screen on some way
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Try adding a timer on the splash window that brings the window to the front. That way, the user can close the splash screen if it's still open.
Avatar of mastiSoft
mastiSoft

ASKER

no it is not acceptable solution, splash screen have to be closed automatically
That's fine but we first have to figure out if it's still open. The timer will show you that.

Otherwise you'll have to share your code so we can see how you're referencing the windows.
nice but how I figure out if it is still open from MainWindow?
I don't think I understand your question.

If you shut down the application, all windows within the application will be closed. A window cannot just remain open if its application closes.

So if you're running it a second time and it doesn't load up properly, then perhaps it didn't actually shut down. Given that it's difficult to debug since it's on a tablet, I'd suggest writing a log somewhere for startup and shutdown processes and then reviewing what it says when you start the application for the second time.

Then see if you're truly calling the shutdown properly, or if you're just putting the app to sleep.
Yes it works like this on PC and Laptop but not on the tablet. I cannot explain why, it just happens. Until I tested software on tablet I din't even though this can be problem.
I used this code to close application:
Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
Application.Current.Shutdown();
and this one :
this.Close();
Works perfect on PC but on tablet when main form close and application in principle have to shut down I still see the Splash window on the screen.
I would suggest creating a copy of your project and stripping out everything but the code that opens and closes the windows and shuts down the application. Then see if the stripped-down copy still has the same behavior on the tablet.

If it does, then please share the stripped-down project here.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.