Problem with form execution

kaveh rahimi 61 Reputation points
2021-05-22T15:46:59.763+00:00

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()

    Application.Run(Form1)
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)
Console.WriteLine("ok")
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
        Try
            pluggedInQuery = New WqlEventQuery
            pluggedInQuery.QueryString = "SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 2"
            pluggedInWatcher = New ManagementEventWatcher(pluggedInQuery)
            pluggedInWatcher.Start()

            pluggedOutQuery = New WqlEventQuery
            pluggedOutQuery.QueryString = "SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 3"
            pluggedOutWatcher = New ManagementEventWatcher(pluggedOutQuery)
            pluggedOutWatcher.Start()
        Catch ex As Exception
            MsgBox(ex.Message)
        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
Thanks

VB
VB
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