Sto cercando di impostare il timer nella mia app di Windows Store.Come impostiamo i timer nell'app WinRT?
public void Start_timer()
{
Windows.UI.Xaml.DispatcherTimer timer = new DispatcherTimer();
timer.Tick += new Windows.UI.Xaml.EventHandler(timer_Tick);
timer.Interval = new TimeSpan(00, 1, 1);
bool enabled = timer.IsEnabled; // Enable the timer
timer.Start(); // Start the timer
}
Sul pulsante clic Ho chiamato sopra il metodo per impostare questo timer. Ma quando viene impostato Eventhandler for Tick, viene visualizzato l'errore "Tentativo di leggere o scrivere memoria protetta. Ciò è spesso un'indicazione che un'altra memoria è corrotta."
È necessario gestire i timer in modo diverso nelle app di Windows Store?
Cosa succederà se si imposta il timer su un campo e il timer. Su + = timer_Tick; timer.Interval = new TimeSpan (00, 1, 1); passare al contructor. Anche bool enabled = timer.IsEnabled; non ha alcun effetto, vero? –
@lukas Spiacente, non ho ottenuto il tuo primo punto. Potresti elaborare – Sap
timer DispatcherTimer privato = new DispatcherTimer(); public YourClass() { timer.Tick + = timer_Tick; timer.Interval = new TimeSpan (00, 1, 1); } –