Mình có đoạn code:
private void button_Click(object sender, RoutedEventArgs e)
{
System.Timers.Timer asd = new System.Timers.Timer(6000);
asd.Elapsed += new System.Timers.ElapsedEventHandler(asdasd);
asd.Start();
}
private void asdasd(object sender, System.Timers.ElapsedEventArgs e)
{
this.Close();
MessageBox.Show("đã đóng cửa sổ");
}
Mục đích của nó là: Khi click vào button thì sau 6 giây cửa sổ MainWindow sẽ đóng lại
và xuất hiện 1 MessageBox với dong chữ “đã đóng cửa sổ”.
Nhưng đến dòng this.Close(); thì nó báo lỗi:
An exception of type ‘System.InvalidOperationException’ occurred in WindowsBase.dll but was not handled in user code
Có ai biết thì giúp mình với ạ. hoặc có cách nào hay hơn cũng đc.
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?