473,385 Members | 1,693 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,385 software developers and data experts.

Terminating active threads in Multi-threaded application question

Hi,

I'm working on a multi-threaded application. I'm using ThreadPools.

One of the requirements of the application is, if certain exception occurs
all the
counters have to be reset. I have noticed that some threads, even after
resetting
the counters, have the old values.

Is there any way that we can disable/abort/kill all the active threads when
certain exception occurs.

How can we make sure that the all the counters are synchronised in all
threads.
As I have to port this code to Windows CE platform later on, I guess
aborting
threads may not be one option.

please let me know your suggestions for this scenario.

Cheers,

Naveen.
Nov 17 '05 #1
2 1913
Hey Naveen

What kine of Thread synchronization module are you using (if any).

Synchronizing threads is not so trivial. Try using Mutex, Monitor class,
lock etc. to synchronize your objects in a multi-threaded environment (Check
MSDN).

You can use ManualResetEvent and AutoResetEvent to synchronize events
between threads to cancel threaded operation in your threadStart delegate.

private void ThreadedMethod
{
while (true)
{
// Wait for cancelation Event for 100 ms. This event should be set
in other // thread
if [AutoResetEvent variable].WaitOne(100)
{
//Cancel the method, reset counters or what so ever
}
else
{
//Continue your method..
}
}
}

Hope this helps.

- Moty -

"Naveen Mukkelli" <Na************@discussions.microsoft.com> wrote in
message news:40**********************************@microsof t.com...
Hi,

I'm working on a multi-threaded application. I'm using ThreadPools.

One of the requirements of the application is, if certain exception occurs
all the
counters have to be reset. I have noticed that some threads, even after
resetting
the counters, have the old values.

Is there any way that we can disable/abort/kill all the active threads
when
certain exception occurs.

How can we make sure that the all the counters are synchronised in all
threads.
As I have to port this code to Windows CE platform later on, I guess
aborting
threads may not be one option.

please let me know your suggestions for this scenario.

Cheers,

Naveen.

Nov 17 '05 #2
hi,

Take a look at Skeet's articles about that. There you will find an answer
to all your questions

http://www.yoda.arachsys.com/csharp/threads/

It does include sync. how to kill a thread and locking strategies

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Naveen Mukkelli" <Na************@discussions.microsoft.com> wrote in
message news:40**********************************@microsof t.com...
Hi,

I'm working on a multi-threaded application. I'm using ThreadPools.

One of the requirements of the application is, if certain exception occurs
all the
counters have to be reset. I have noticed that some threads, even after
resetting
the counters, have the old values.

Is there any way that we can disable/abort/kill all the active threads
when
certain exception occurs.

How can we make sure that the all the counters are synchronised in all
threads.
As I have to port this code to Windows CE platform later on, I guess
aborting
threads may not be one option.

please let me know your suggestions for this scenario.

Cheers,

Naveen.

Nov 17 '05 #3

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

Similar topics

6
by: Thomas Womack | last post by:
If I have a dual-processor hyperthreaded machine (so with four CPU contexts), will a python program distribute threads over all four logical processors? I ask because I'm fairly sure that this...
11
by: Przemysław Różycki | last post by:
Hello, I have written some code, which creates many threads for each connection ('main connection'). The purpose of this code is to balance the load between several connections ('pipes'). The...
0
by: arifvahora | last post by:
Active Server Pages error 'ASP 0240' Script Engine Exception work.asp A ScriptEngine threw exception 'C0000005' in 'IActiveScript::SetScriptState()' from...
1
by: Zeng | last post by:
Hello, If I have an object that exposes many methods which don't change anything about the object (at least I'm not aware in terms of implementation of the ..net class). The methods are called...
23
by: Adam Clauss | last post by:
I have a C# Windows Service running as the NetworkService account because it needs to access a network share. As part of the service's initialization, I want the service to terminate, if an...
0
by: JJ | last post by:
I need to allow the user to cancel a thread. The examples I've seen seem to set a 'cancel requested' flag in a while..do loop in the threads code. However, my threads task is a mainly a single...
0
markryan57
by: markryan57 | last post by:
Greetings, I have seen different ideas on how to terminate active processes (i.e., MS Access, Excel, etc) from VB6 - what is the most effecient method of finding and terminating active processes? ...
1
by: sweety_s | last post by:
I need to get the list of active threads in a process. I have used NtQuerySystemInformation API with SystemProcessInformation but i get all the no: of threads in the process, but i dont get the...
167
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an...
4
by: jake | last post by:
I am new to multi-threading. Here is my scenario: foreach (<file in a certain folder>) new Thread((ThreadStart)(delegate { processFile(<file>); })).Start(); sometimes misses firing some...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.