Problem with form execution

kaveh rahimi 61 Reputation points

Hi ,when I have a form class in my code the other lines except 'public class form1' don't execute.
I don't know why it's so.for example my code is:
Imports System.Management
Imports Microsoft.Win32
Imports System.Windows.Forms

Public Class mainclass
Public Shared Sub dosomething()
Task.Run(Sub() updateform())
End Sub
Public Delegate Sub formdelegate()
Public Shared Sub updateform()

End Sub

Private Declare Function ch341open Lib "ch341dll.dll" (ByVal iindex As Integer) As Integer

End Class

Module module1
Sub main()
Application.Run(New Form1)
End Sub
End Module
Public Class Form1
Dim WithEvents pluggedInWatcher As ManagementEventWatcher
Dim WithEvents pluggedOutWatcher As ManagementEventWatcher
Dim pluggedInQuery As WqlEventQuery
Dim pluggedOutQuery As WqlEventQuery

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            pluggedInQuery = New WqlEventQuery
            pluggedInQuery.QueryString = "SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 2"
            pluggedInWatcher = New ManagementEventWatcher(pluggedInQuery)

            pluggedOutQuery = New WqlEventQuery
            pluggedOutQuery.QueryString = "SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 3"
            pluggedOutWatcher = New ManagementEventWatcher(pluggedOutQuery)
        Catch ex As Exception
        End Try
    End Sub

    Private Sub pluggedInWatcher_EventArrived(sender As Object, e As EventArrivedEventArgs) Handles pluggedInWatcher.EventArrived
        MsgBox("Plugged In")
    End Sub

    Private Sub pluggedOutWatcher_EventArrived(sender As Object, e As EventArrivedEventArgs) Handles pluggedOutWatcher.EventArrived
        MsgBox("Plugged Out")
    End Sub
End Class

Please help

An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,496 questions
{count} votes