I'm working in a Xamarin Forms project, using Prism DryIoc.
For example, i have a MainPage
, and a APage
, with ViewModels
MainPageViewModel
and APageViewModel
. In APageViewModel
i have a timer as simple as the code below:
private Timer _timer;
public override void Initialize(INavigationParameters parameters)
{
base.Initialize(parameters);
_timer = new Timer(1000);
_timer.Elapsed += (sender, args) =>
{
Debug.WriteLine($"{DateTime.Now.ToString(CultureInfo.InvariantCulture)}: Timer run");
};
_timer.Start();
}
When i navigate from MainPage to APage using NavigationService.PushAsync
, the timer start. But when excute NavigationService.GoBackAsync
from APageViewModel
, the timer not stop if i dont manual stop the timer with _timer.Stop()
. So i wonder if the APageViewModel
being properly dispose to clear resources that being use in the view model?