473,788 Members | 2,919 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1928
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 ManualResetEven t 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.mi crosoft.com> wrote in
message news:40******** *************** ***********@mic rosoft.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.mi crosoft.com> wrote in
message news:40******** *************** ***********@mic rosoft.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
7452
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 *does* happen using the threading extensions in MFC, and fairly sure that it *doesn't* when using Java, so I don't see that the result is obvious for python. Tom
11
4203
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 number of spawned threads depends on how many pipes I create (= 2*n+2, where n is the number of pipes). For good results I'll presumably share main connection's load between 10 pipes - therefore 22 threads will be spawned. Now if about 50
0
2367
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 'CActiveScriptEngine::ReuseEngine()'.
1
1391
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 by many threads at the same time. What sort of things that I need to do to make sure the methods and the class are multi-thread safe? I thought I don't need to do anything but I might be wrong. For example, I remember reading from some help file...
23
7595
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 unrecoverable error occurs. When that case occurs, I create a ServiceController object and call the Stop() method. However - I get an exception thrown saying access denied. If I switch to using the LocalService account it works fine, but I lose...
0
970
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 command that collects remote data - would this approach format work in this case? If not, what approach should I use? While Not CancelThread.WaitOne(0, False) And LoopCount < Loops ' Long data collecting task here....
0
952
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? Thanks for the help.. mark
1
2304
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 list of active threads but all the threads in the process. Could any one please help me with this problem
167
8357
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 object should run in its own thread, it should implement this mix-in class. Does this sound like plausible design decision? I'm surprised that C++ doesn't have such functionality, say in its STL. This absence of a thread/object relationship in...
4
1284
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 threads to process files. It misses firing different threads every time I run it. I suppose it all depends on the time-slice it is getting at that moment (or I may be way off base here). What I mean by "misses" is that the "foreach" loop appears to...
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5402
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.