views:

200

answers:

1

Hi, 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

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.

+2  A: 

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.

Jonathan Allen