Question Rising events from class library called from module

seinkraft

Member
Joined
Sep 28, 2008
Messages
19
Programming Experience
5-10
Hi, I've the next problem.

I've an app that starts to work from a module wich should load a form an do other things with a class library who raise an event an the form shoud cath it.

The problem is that applicarion.run(frmMain) displays the form in the same thread the the code stops work while the form is open. And I need that the app works in this way because the user need to send files to the app using args and this avoid that the app init another instance of it (in other code) and update the form with the info when the event is raised.

Please help :(

Module
VB.NET:
Module moMain

    Public my_Class As New ClassDll.clsMain

    Public Sub main()

        Application.Run(frmMain)
        Debug.WriteLine("Form Loaded")

        my_Class.DoSomething()

    End Sub

End Module

Class
VB.NET:
Public Class clsMain

    Public Event EventRaise()

    Public Sub DoSomething()
        RaiseEvent EventRaise()
    End Sub

End Class

Form
VB.NET:
Public Class frmMain

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler my_Class.EventRaise, AddressOf raised_from_class
    End Sub

    Public Sub raised_from_class()
        MsgBox("event raised")
    End Sub

End Class

The code is also attached without compiled files.
 

Attachments

  • Events.zip
    18.5 KB · Views: 18
Last edited by a moderator:
Yes I know, but the application should load files from windows context menu, if the user load 50 files appears 50 windows wich 49 get closed because the aplication want only one instance.

Using this way the application only appears once and the files are added to a waiting list to be processed.
 
When app is single-instance StartupNextInstance is raised in the existing instance if there is one, else Startup event is raised as normal when app first starts up.
 
Yep, i'm following the example from msdn buyt it doesn't work :S

VB.NET:
Imports Microsoft.VisualBasic.ApplicationServices

Public Class Form1

    Public Event StartupNextInstance As StartupNextInstanceEventHandler

    Private Sub MyApplication_StartupNextInstance(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs) Handles Me.StartupNextInstance
        MsgBox("Test")
    End Sub


End Class
 
Last edited:
The example works, your following doesn't ;)
 
Start a new project, follow the "To access the Code Editor window for application events" guide in StartupNextInstance help article, add the code example provided. Done.
 
Back
Top