.NETのメッセージボックス
.NETのFormとかWPFなどのGUIでは、UIイベント処理中は普通は他のイベントは処理されない。ただし、メッセージボックス表示中はTimer.Tick等は動いてしまう。
参考:Timer.Tick イベントでMessageBoxを呼ぶと死ぬ件について(https://lets-csharp.com/death-of-messagebox/)
しかし、常にそうとは限らないようだ。
WPFで以下のようなコードを書くと、DefaultDesktopOnlyの場合だけ、メッセージボックス表示中にtimer_Tickが呼ばれていないようだ。
Class MainWindow
Private timer as System.Windows.Threading.DispatcherTimer
Private Sub Window_Loaded(sender as Object, args as EventArgs)
timer = new System.Windows.Threading.DispatcherTimer
timer.Interval = TimeSpan.FromMilliseconds(200)
AddHandler timer.Tick, AddressOf timer_Tick
timer.Start()
End Sub
Private Sub timer_Tick(sender as Object, args as EventArgs)
ClockText.Text = DateTime.Now.ToString("HH:mm:ss")
End Sub
Private Sub ButtonClick(sender as Object, args as RoutedEventArgs)
Dim btn = DirectCast(sender, Button)
If btn.Name = "Sleep" Then
ClockText.Text = "Sleeping"
Threading.Thread.Sleep(2000)
ElseIf btn.Name = "MBox" Then
MessageBox.Show("Default")
ElseIf btn.Name = "DefaultDesktopOnly" Then
MessageBox.Show("DefaultDesktopOnly", "DefaultDesktopOnly", MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.None, MessageBoxOptions.DefaultDesktopOnly)
ElseIf btn.Name = "VBMBox" Then
MsgBox("VB Default")
ElseIf btn.Name = "SystemModal" Then
MsgBox("SystemModal", MsgBoxStyle.SystemModal)
End If
End Sub
End Class
コメント
コメントを投稿