I have a Window
that only has one frame to show the different pages that my application has.
When a Page loads
, it initializes several threads that deal with different elements of the UI. When I change the page with frame.Navigate(new NextPage())
I abort those threads, as it doesn't make sense to keep them running when the page is not in the foreground.
The problem comes when I make frame.GoBack()
, since I have no way to relaunch those treads on the page because no code is executed when I return to the page.
There is something similar to the OnPause, OnStart, OnStop method of Android but for WPF and pages?
Something like the following:
public MainPage()
{
InitializeComponent();
var thread = new Thread(() => Code());
thread.Start();
}
public Code()
{
// Do Stuff
}
public Continue()
{
thread.abort()
frame.Navigate(new NextPage())
}
public OnPageReloaded()
{
thread.start()
}