Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi community, i been run into a lot of problems i can't solve when i use an alternative message pump, from events not firing till fields being altered on it's own and classes not being instantiated or not running correctly.
Since i don't want to use a Windows.Form and want my App to operate more or less similarly as a service but not completely. I have selected Windows Forms Application and disabled Application Framework, i have selected to start from a Module. And because my App needs a message pump i have written to not be closed by itself, rather operate like a Windows Form without a Window. I don't know what is the problem, maybe the Threads are conflicting, but then again there is no exception thrown. See the code:

VB
Module Module1
Sub Main
         Dim absClass As New InheritorClass()
End Sub
End Module

Class AbstractClass
 Sub New()
        Me.Start()
 End Sub

   WithEvents MainTimer As New System.Timers.Timer
    Public Event Load()

    Private Sub Start()
        System.Console.WriteLine("Application has started.") 
        MainTimer.Interval = 5000
        MainTimer.Start()
          RaiseEvent Load()
        Application.Run()
          RaiseEvent Load()
    End Sub
    Sub Close()
        System.Console.WriteLine("Application will exit.")
        Application.Exit()
    End Sub
Dim retriesLeft As Integer = 10

    Private Sub MainTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles MainTimer.Elapsed 
        If retriesLeft > 0 Then
            System.Console.WriteLine(String.Format("{0} retries remaining...", retriesLeft))
            retriesLeft = retriesLeft - 1
        Else
            ' This stops the message pump, closing your application
            'Application.Exit()
            Me.Close()
        End If

    End Sub 
End Class

Class InheritorClass : Inherits AbstractClass
  Sub New()
   MyBase.New()
  End Sub

  Private Sub Me_Load() Handles Me.Load
   MsgBox("App has loaded") ' NEVER GETS TRIGGERED
  End Sub

End Class



I have managed to modify the code to make it work using methods by directly calling but then some of the fields get altered or nullified on their own etc. Also calling other Classes from the InheritorClass is not possible.

What I have tried:

--------------------------------------------------------------------------------------
Posted
Updated 25-Sep-17 15:52pm
v4
Comments
Richard MacCutchan 25-Sep-17 12:12pm    
Sounds like it is time for a total rethink of your design. If you don't stick to the rules in Windows then things may, or may not, work. If they do not then you need to look at why.

1 solution

Doing a little Google Search research[^], it is possible to achieve what you want but the approach is slightly different. Have a read of this StackOverflow thread[^]. It should have most, if not all the answers that you are and will be looking for.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900