473,324 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

terminate threads in managed c++

Hi I have thread that recives event notifications from a server.

the thread is created as a managed thread. But when using Thread Abort the
thread doesn't terminate.

the thread is in an waitable state using WSAWaitForMultipleEvents.

How can I kill this thread, i don't mind brute force.

/Steffo
Nov 16 '05 #1
5 3951
<S> wrote in message news:e3**************@TK2MSFTNGP11.phx.gbl...
Hi I have thread that recives event notifications from a server.

the thread is created as a managed thread. But when using Thread Abort the
thread doesn't terminate.

the thread is in an waitable state using WSAWaitForMultipleEvents.

How can I kill this thread, i don't mind brute force.

/Steffo


Hi Steffo,

You can't! Use a timeout with WaitForMultipleEvents and then use this
information

http://groups.google.com/groups?hl=e....nl%26rnum%3D1

to check if the CLR wants your thread to abort. ExitThread can then be
called.

Ferdinand.
Nov 16 '05 #2
> How can I kill this thread, i don't mind brute force.

This is a design flaw. Please redesign your threads to shutdown by logic,
not by force.
--
Regards,
Lars-Inge Tonnessen
http://emailme.larsinge.com
http://www.larsinge.com
Nov 16 '05 #3
Maybe yoy could give me an example, on how it should be done.

/Steffo

"Lars-Inge Tønnessen" <http://emailme.larsinge.com> skrev i meddelandet
news:Oe*************@tk2msftngp13.phx.gbl...
How can I kill this thread, i don't mind brute force.


This is a design flaw. Please redesign your threads to shutdown by logic,
not by force.
--
Regards,
Lars-Inge Tonnessen
http://emailme.larsinge.com
http://www.larsinge.com

Nov 16 '05 #4
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?

--
Regards,
Lars-Inge Tonnessen
http://emailme.larsinge.com
http://www.larsinge.com
Nov 16 '05 #5
Yes I suppose it did. Tanks!

/stefan
"Lars-Inge Tønnessen" <http://emailme.larsinge.com> skrev i meddelandet
news:uc**************@TK2MSFTNGP10.phx.gbl...
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?

--
Regards,
Lars-Inge Tonnessen
http://emailme.larsinge.com
http://www.larsinge.com

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: WinstonSmith | last post by:
Hallo everyone, is there a way to get a list of all threads an application written in C# uses? Thanks in advance Matthias
4
by: Dr. J | last post by:
How to terminate a blocked thread? In my form's "load" I launch a TCP listening thread that stays in an infinite loop waiting for incoming TCP packets. In this form's "closing" I try to...
2
by: Tom | last post by:
hi friends is there a way to terminate all threads in one go ? Thanks Tom
3
by: bygandhi | last post by:
Hi - I am writing a service which will check a process and its threads for their state ( alive or dead ). The process has 5 .net managed threads created using thread.start and each have been...
3
by: Kathy Burke | last post by:
Hi, I'm tired, so this question may be silly. I have a fairly long sub procedure. Based on one condition, I load another sub with the following: If Session("GRN") = "complete" Then txtScan.Text...
9
by: Li Pang | last post by:
Hi I make an app which can run some sub processes through multiple threads. I'd like to know how to terminate all sub-threads when the main thread is closed thanks in advance
10
by: Darian | last post by:
Is there a way to find all the thread names that are running in a project? For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and T5 are running...I want to be able to know that...
5
by: Benny | last post by:
I have a ASP.NET webservice and it is configured to run in a web garden with multiple processes. Whan a process in the garden is launched, I want the process to create a background thread. When...
2
by: R. Nachtsturm | last post by:
Hi, i have the problem that when i create a low priority background thread, start it, and wait for it to finish that it does not seem to terminate even after it is finished.. if i use...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.