You are mixing managed code (threding) with unmaganed code
(WSAWaitForMultipleEvents) . You are killing a managed code that has
unmanaged logic, this could be the reason it does not work. Maybe the
unmanaged code spinns off a new thread in some libraries... Anyway killing a
thread is a design flaw.
Send a "thread shutdown" event to the thread and your event-handler. Use
this event to break out of the event handler loop and let the thread die on
its own. How you design this "thread shutdown event" is up to you. The
framework does not give you this.
Use signals/events in the main thread so the main thread does not shutdown
before all child threads have died on their own.
Or you could make a timeout on the waiting call and use a shared variable
(critical section) with the mail thread, to control the event handler loop
to let the thread die on its own.
The solution is to design the thread to die on its own, and don't shutdown
the main thread before all child threads have died. Use event/signal to
achieve this. Eg store all threads in a vector/list structure so you easily
can traverse this structure before you shutdown the main thread/app.
Did this make any sense?