开发者

How to raise events from class library to form using module?

开发者 https://www.devze.com 2022-12-18 06:10 出处:网络
i\'ve a app that starts from a sub in a module, do a few things, and then load the form. But it doesn\'t work :/

i've a app that starts from a sub in a module, do a few things, and then load the form.

But it doesn't work :/

Here we execute dBase.AddTemporalFilepath

module.vb

Public dBase As New Core.clsDatabase

Public Sub Main()

    FurBase.Directory = My.Application.Info.DirectoryPath

    If appMutex.WaitOne(TimeSpan.Zero, True) Then
        ShowUploader()
    End If

    Dim returnValue As String()

    returnValue = Environment.GetCommandLineArgs()

    If returnValue.Length > 1 Then
        If My.Computer.FileSystem.FileExists(returnValue(1).ToString) Then
            dBase.AddTemporalFilepath(returnValue(1).ToString)
        End If
    End If

End Sub

Private Sub ShowUploader()
    Application.EnableVisualStyles()
    Application.Run(frmUploader)
End Sub

We raise the event TempFilepathAdded

clsDatabase.vb

Public Class clsDatabase

Public Event TempFilepathAdded()

Public Function AddTemporalFilepath(ByVal filepath As String)
...
        RaiseEvent TempFilepathAdded()
...
End Function

End Class

开发者_Go百科We catch the event

form.vb

Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    AddHandler dBase.TempFilepathAdded, AddressOf TempFilepathAddedHandler

End Sub

Private Sub TempFilepathAddedHandler()
    MsgBox("Event raised")
End Sub

Any Idea?

More info:

The event is raised when the form is closed.


The line "Application.Run(frmUploader)" pauses your program until the Window closes. Basically it hijacks the main thread to handle stuff like users clicking buttons.

Normally your Main function should look like this:

  1. Setup
  2. Application.Run
  3. Clean-up

Sorry, but it looks like its time to reorganize your code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号