Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

RaiseEvent Doesn't Trigger Until After Thread Ends

Avatar of Javin007
Javin007Flag for United States of America asked on
.NET ProgrammingVisual Basic.NETMicrosoft Development
9 Comments1 Solution692 ViewsLast Modified:
I'm trying to fire off an event in a thread, and have it update a user interface in the parent thread.  While the code *technically* works, the delay in the event triggers is completely unacceptable.  

I have the following code that spawns the thread in a class that's created "withevents":
        RaiseEvent Lock_On(parTemp.ID, strTemp, intTemp)
        Debug.Print(System.Environment.TickCount & " - 'ON' Event Raised: " & parTemp.ID)
        thrTemp.Start(parTemp)
This event is triggered when the code finishes running:
        RaiseEvent Lock_Off(Params.ID, strTemp, Threads.Unlock(strTemp))
        Debug.Print(System.Environment.TickCount & " - 'OFF' Event Raised: " & Params.ID)

Then in the main class, here are the events:
    Private Sub p1_Lock_On(ByVal Index As Int64, ByVal Name As String, ByVal Thread As Int64) Handles p1.Lock_Off
        Debug.Print(System.Environment.TickCount & " - Received 'ON' Event " & Index)
    End Sub
    Private Sub p1_Lock_Off(ByVal Index As Int64, ByVal Name As String, ByVal Thread As Int64) Handles p1.Lock_Off
        Debug.Print(System.Environment.TickCount & " - Received 'OFF' Event " & Index)
    End Sub

The end result is the following:
     469494609 - 'ON' Event Raised: 1
     469529015 - Received 'OFF' Event 1
     469529015 - Received 'ON' Event 1
     469529062 - 'OFF' Event Raised: 1


As you can see, the "ON" event is being raised, but it's a full 6+ seconds before it's actually RECEIVED by the event handler.  It doesn't actually get received until AFTER the "OFF" event is triggered, either.  Even the raising of the "OFF" event happening AFTER the receiving of the event is somewhat confusing.

Can someone please shed some light on this one?  How do I get the events to trigger WHEN they are actually called?  Otherwise, they're useless.  I may as well just stick all my "on" and "off" code in the same sub and run it at the end of the event.  >:(  Obviously this can be done SOMEHOW since the Debug is getting updated in real-time.
ASKER CERTIFIED SOLUTION
Avatar of graye
grayeFlag of United States of America image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answers