Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Urgent and Interesting!!! EventHandling Bug!!!????

Urgent and Interesting!!! EventHandling Bug!!!????

Scheduled Pinned Locked Moved Visual Basic
helpcsharptutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yurcus
    wrote on last edited by
    #1

    I have an object that fires an event and a form that handles that event. When handling the event i show a new form but the new form hangs. It gets "Loaded", "VisibleChanged" and "Activated" events and hangs. I am attaching vb code as an example. Please see and if you can figure out why it is so i will really appreciate if you tell me. Thanks in advance!!!! P.S. as I understand its a bug - the form must show without problems!!! here is the sample code of the error in vb.net:))) 'Class EventRaiser raises SomeEvent 3 seconds after it is loaded. 'EventHandlerForm handles that event and shows modeless form. 'Normally the new form must have no problems but actually it 'receives "Load", "VisibleChanged" and "Activated" events and hangs. 'Raises event "SomeEvent" 3 seconds after it is created. Public Class EventRaiser Public Event SomeEvent() Private WithEvents myTimer As New System.Timers.Timer() Sub New() myTimer.Interval = 3000 myTimer.Start() End Sub Private Sub mytimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles myTimer.Elapsed RaiseEvent SomeEvent() myTimer.Enabled = False End Sub End Class Public Class EventHandlerForm Inherits System.Windows.Forms.Form 'EventRaiser raises SomeEvent 3 seconds after it is created. Private WithEvents myEventRaiser As New EventRaiser() #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label() Me.Suspend

    D M 2 Replies Last reply
    0
    • Y Yurcus

      I have an object that fires an event and a form that handles that event. When handling the event i show a new form but the new form hangs. It gets "Loaded", "VisibleChanged" and "Activated" events and hangs. I am attaching vb code as an example. Please see and if you can figure out why it is so i will really appreciate if you tell me. Thanks in advance!!!! P.S. as I understand its a bug - the form must show without problems!!! here is the sample code of the error in vb.net:))) 'Class EventRaiser raises SomeEvent 3 seconds after it is loaded. 'EventHandlerForm handles that event and shows modeless form. 'Normally the new form must have no problems but actually it 'receives "Load", "VisibleChanged" and "Activated" events and hangs. 'Raises event "SomeEvent" 3 seconds after it is created. Public Class EventRaiser Public Event SomeEvent() Private WithEvents myTimer As New System.Timers.Timer() Sub New() myTimer.Interval = 3000 myTimer.Start() End Sub Private Sub mytimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles myTimer.Elapsed RaiseEvent SomeEvent() myTimer.Enabled = False End Sub End Class Public Class EventHandlerForm Inherits System.Windows.Forms.Form 'EventRaiser raises SomeEvent 3 seconds after it is created. Private WithEvents myEventRaiser As New EventRaiser() #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label() Me.Suspend

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      There is something about creating the new form inside that event handler. Creating the few form inside the handler for a button works perfectly, but not inside the myEventRaiser.SomeEvent handler for some reason. RageInTheMachine9532

      1 Reply Last reply
      0
      • Y Yurcus

        I have an object that fires an event and a form that handles that event. When handling the event i show a new form but the new form hangs. It gets "Loaded", "VisibleChanged" and "Activated" events and hangs. I am attaching vb code as an example. Please see and if you can figure out why it is so i will really appreciate if you tell me. Thanks in advance!!!! P.S. as I understand its a bug - the form must show without problems!!! here is the sample code of the error in vb.net:))) 'Class EventRaiser raises SomeEvent 3 seconds after it is loaded. 'EventHandlerForm handles that event and shows modeless form. 'Normally the new form must have no problems but actually it 'receives "Load", "VisibleChanged" and "Activated" events and hangs. 'Raises event "SomeEvent" 3 seconds after it is created. Public Class EventRaiser Public Event SomeEvent() Private WithEvents myTimer As New System.Timers.Timer() Sub New() myTimer.Interval = 3000 myTimer.Start() End Sub Private Sub mytimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles myTimer.Elapsed RaiseEvent SomeEvent() myTimer.Enabled = False End Sub End Class Public Class EventHandlerForm Inherits System.Windows.Forms.Form 'EventRaiser raises SomeEvent 3 seconds after it is created. Private WithEvents myEventRaiser As New EventRaiser() #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label() Me.Suspend

        M Offline
        M Offline
        mikasa
        wrote on last edited by
        #3

        You "Dim"-ed the Form variable inside the Event Handler. Remember that anytime a Routine goes out of Scope, the Variables in that Routine also get destroyed. This could be causing the problem. Dim the Form variable outside of the Event Handler routine. Hope that helps!

        Y 1 Reply Last reply
        0
        • M mikasa

          You "Dim"-ed the Form variable inside the Event Handler. Remember that anytime a Routine goes out of Scope, the Variables in that Routine also get destroyed. This could be causing the problem. Dim the Form variable outside of the Event Handler routine. Hope that helps!

          Y Offline
          Y Offline
          Yurcus
          wrote on last edited by
          #4

          I've tried that already. But in the example i use System.Timers.Timer class. If i use the System.Windows.Forms.Timer then it works ok. I want to understand whats the difference in the events???

          M 1 Reply Last reply
          0
          • Y Yurcus

            I've tried that already. But in the example i use System.Timers.Timer class. If i use the System.Windows.Forms.Timer then it works ok. I want to understand whats the difference in the events???

            M Offline
            M Offline
            mikasa
            wrote on last edited by
            #5

            Ahh, Ok, then this might be because the System.Timers work on a separate Thread. The Windows.Forms.Timer works because it's on the same thread as the UI. In your Code you need to say "Me.Invoke(..." in order to get your new Form loaded into the MAIN UI Thread. Other wise, it's loading your new Form into a separate Thread in which you cannot control this new Form. Read up on Multithreading...a good example is the Chat application in the MSDN.

            Y 1 Reply Last reply
            0
            • M mikasa

              Ahh, Ok, then this might be because the System.Timers work on a separate Thread. The Windows.Forms.Timer works because it's on the same thread as the UI. In your Code you need to say "Me.Invoke(..." in order to get your new Form loaded into the MAIN UI Thread. Other wise, it's loading your new Form into a separate Thread in which you cannot control this new Form. Read up on Multithreading...a good example is the Chat application in the MSDN.

              Y Offline
              Y Offline
              Yurcus
              wrote on last edited by
              #6

              I get it now!!:))) Thanks a lot!!!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups