Handles
句に WithEvents
変数を指定していません。 プロシージャ宣言の最後にある Handles
キーワードによって、WithEvents
キーワードを使用して宣言されたオブジェクト変数によって発生したイベントが処理されるようになります。
エラー ID: BC30506
このエラーを解決するには
必要な WithEvents
変数を指定します。
例
次の例では、Visual Basic によってコンパイラ エラー BC30506
が生成されます。これは、System.Timers.Timer インスタンスの定義で WithEvents キーワードが使用されていないためです。
Imports System.Timers
Module Module1
Private _timer1 As New Timer() With {.Interval = 1000, .Enabled = True}
Sub Main()
Console.WriteLine("Press any key to start the timer...")
Console.ReadKey()
_timer1.Start()
Console.ReadKey()
End Sub
Private Sub Timer1_Tick(sender As Object, args As EventArgs) Handles _timer1.Elapsed
Console.WriteLine("Press any key to terminate...")
End Sub
End Module
次の例では、_timer1
変数が WithEvents
キーワードで定義されているため、正常にコンパイルされます。
Imports System.Timers
Module Module1
Private WithEvents _timer1 As New Timer() With {.Interval = 1000}
Sub Main()
Console.WriteLine("Press any key to start the timer...")
Console.ReadKey()
_timer1.Start()
Console.ReadKey()
End Sub
Private Sub Timer1_Tick(sender As Object, args As EventArgs) Handles _timer1.Elapsed
Console.WriteLine("Press any key to terminate...")
End Sub
End Module
関連項目
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET