2017-01-18 6 views
0

私は楽しいと私はNotficationWindow.Show()を使用してウィンドウを呼び出すしようとしているプログラムを作っていると私はそれをスリープを使用して設定時間後に閉じて、エラー:Cannot set Visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after a Window has closed.ではなく、最良の方法、それは彼らがイム幸せ動作するかどうか、ここに私のコードがありますので、それが私的使用のためです:
メインウィンドウ: C#でリモートで開いた後にウィンドウを閉じることができませんWPF

private void ShowNoti_Click(object sender, RoutedEventArgs e) 
{ 
    XuriNotification Noti = new XuriNotification(); 
    Noti.Show(); 
} 

XuriNotification.xaml.cs:

public XuriNotification() 
{ 
    InitializeComponent(); 
    var desktopWorkingArea = System.Windows.SystemParameters.WorkArea; 
    this.Left = desktopWorkingArea.Right - this.Width; 
    this.Top = desktopWorkingArea.Bottom - this.Height; 

    System.Threading.Thread.Sleep(2000); 
    System.Windows.Forms.Application.Exit(); 
} 

答えて

1

DispatchTimerクラスをXuriNotificationクラスに追加し、その間隔を設定する方がよいでしょう。そして、それにTickイベントだ、通知を閉じる:

System.Windows.Threading.DispatcherTimer dispatcherTimer; 

public XuriNotification() 
{ 
    InitializeComponent(); 
    var desktopWorkingArea = System.Windows.SystemParameters.WorkArea; 
    this.Left = desktopWorkingArea.Right - this.Width; 
    this.Top = desktopWorkingArea.Bottom - this.Height; 

    dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); 
    dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); 
    dispatcherTimer.Interval = new TimeSpan(0,0,2); 
    dispatcherTimer.Start(); 

} 

private void dispatcherTimer_Tick(object sender, EventArgs e) 
{ 
    System.Windows.Forms.Application.Exit(); 
} 
+0

私はそのコードを使用すると、私はエラーを得なかったが、窓が、私はそれを修正し、 – ZerterCodes

+0

は気にしないで閉じたことがありません – ZerterCodes

関連する問題