2011-02-14 34 views
2

我正在構建我的第一個SL Out of Browser應用程序。說20分鐘不活動後,我想設置我的App.IsAuthenticated = false,並重定向到登錄頁面。Silverlight 4應用程序中的不活動超時示例代碼(使用MVVM)

我已經用google搜索了這個,我已經閱讀了大量討論,討論了使用mousemove/keydown事件處理程序和調度計時器,但是我還沒有看到任何地方顯示如何這樣的代碼舔完成。我使用MVVM,如果這有所作爲(例如代碼會在我的MainViewModel,所以我想要示例代碼來適應該模式)。

任何人都可以提供這樣的示例代碼?這一點很簡單,我確定,但是在上個月我只是在.NET中進行編碼,而且大部分都是SL。

感謝, 斯科特

+0

我想這是它... http://forums.silverlight.net/forums/p/215349/510599的.aspx – 2011-02-14 21:04:53

回答

2

5演示秒計時器:

public partial class MainPage : UserControl 
{ 
    private DispatcherTimer timer; 
    public MainPage() 
    { 
     InitializeComponent(); 
     timer = new DispatcherTimer(){Interval = TimeSpan.FromSeconds(5)}; 
     timer.Tick += (s, e) => { this.textBlock.Text = "Time out"; this.timer.Stop(); }; 
     timer.Start(); 
    } 

    protected override void OnMouseMove(MouseEventArgs e) 
    { 
     base.OnMouseMove(e); 
     timer.Start(); 
    } 

    protected override void OnKeyDown(KeyEventArgs e) 
    { 
     base.OnKeyDown(e); 
     timer.Start(); 
    } 
} 
相關問題