System.Threading.Timer classをご覧ください。それは間隔でタスクをスケジュールすることができます。ページ全体をリロードする例は、(あなたはピノが示唆したように、あなたのページをクリアするために検討すべきである):
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
timer = new Timer(TimerElapsed);
}
// hold the timer in a variable to prevent it from being garbage collected
private Timer timer = null;
private void TimerElapsed(object state)
{
// important: this line puts the timer call into UI thread
Dispatcher.BeginInvoke(() => {
// your code goes here...
// reload the page (this will reload the app and stop the timer!)
HtmlPage.Window.Eval("location.reload()");
});
}
private void button1_Click(object sender, RoutedEventArgs e)
{
// start the timer in 1 second and repeat every 5 seconds
timer.Change(1000, 5000);
}
}
は、コード内のコメントを見ます。クラススコープの変数にTimer
を格納する必要があります。さもなければそれは参照されず、ガベージコレクションされるかもしれません。時限操作でページの内容を変更する場合は、Dispatcher
オブジェクトを使用してUIスレッドに挿入する必要があります。もしあなたがそれをしなければあなたは例外を得るでしょう。
は、私は今、私は、矩形(長方形からページを空にして、再度起動するボタンをクリックして)、私はコードでこれを行うにしたいとの完全なページをリロードしたい、コードがXAMLではない使用して、プログラム的に四角形を作成しました – zaidmctaie