TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Anurag Malani
NA
80
34.6k
If CPU usage is 100% then close the all threads C#
Jun 16 2015 4:09 AM
Hi
Using TPL i am able to consume all cores of my machine, but sometimes the CPU usage reached to 100%. My question is how can we forcefully tell to program the terminate the all threads which are currently using and reset the task again.
Below is my program -
Parallel.For(0, loopCount, parallelOptions, loopno =>
{
for (int i = 0; i < tDSInput.Tables[0].Rows.Count; i++)
{
////////Here i want to chk the CPU usage (if cpu usage is > 95%) then stop all running threads else normal execution.
var locker = new object();
Monitor.Enter(locker);
try
{
var tasks = Task.Factory.StartNew(() => ABC(), TaskCreationOptions.LongRunning)
.ContinueWith(t => DEF(), TaskContinuationOptions.ExecuteSynchronously)
.ContinueWith(t => GHI(), TaskContinuationOptions.ExecuteSynchronously)
.ContinueWith(t => JKL(), TaskContinuationOptions.ExecuteSynchronously)
....
....
....
....
....
....
.ContinueWith(t => XYZ(), TaskContinuationOptions.ExecuteSynchronously)
Task.WaitAll(tasks);
}
finally
{
Monitor.Exit(locker);
}
}
}
How do I do that?
Reply
Answers (
2
)
Set Filter for less secure apps On through metro app
SqlException: The login is from an untrusted domain and cann