trigger an event in a parent thread

Is there a way to trigger an event in a parent thread while the child thread is still running?


I can call a method when the child thread finishes using the asynch callback, but not while its running.


Here is my attempt so far: (which is not working)


    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim objmyAsynch As New my_asynch

        Dim mi As New MethodInvoker(AddressOf objmyAsynch.my_asynch_sub)
        mi.BeginInvoke(AddressOf mycallback_sub, Nothing)
    End Sub

    Public Sub mycallback_sub(ByVal ar As IAsyncResult)
        Console.WriteLine("here")
        Console.WriteLine(ar.AsyncState)
    End Sub

    Public Class my_asynch
        Public Event myEvent()

        Public Sub my_asynch_sub()
            Console.WriteLine("second thread going just fine")
            RaiseEvent myEvent()
        End Sub

    End Class
LVL 4
brokeMyLegBikingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Corey ScheichDeveloperCommented:
You need to move this to your class declarations.

Dim objmyAsynch As New my_asynch

Because you are loosing your reference to this object as soon as the button3_Click sub is finished, it gets garbage collected.  Also you aren't actually creating a second thread these are running in the same thread.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Corey ScheichDeveloperCommented:
Do you need more info?  Did this pose some related questions?
Thank you for the points
brokeMyLegBikingAuthor Commented:
Sorry about the B, guess it should be an A.

I'm just having trouble with threading. It's a big topic.

But I have opened up another question, perhaps you can answer this one?


http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_21485361.html
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.