Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Assemblies
.NET Core
.NET Standard
Active Directory
ADO.NET
Agile Development
AJAX
Alexa Skills
Algorithms in C#
Android
Angular
Architecture
ArcObject
Artificial Intelligence
ASP.NET
ASP.NET Core
Augmented Reality
Aurelia
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blockchain
Bootstrap
Bot Framework
Business
C#
C# Corner
C, C++, MFC
Career Advice
Chapters
CIO
Cloud
COBOL.NET
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Cortana Development
Cryptocurrency
Cryptography
Crystal Reports
Current Affairs
Custom Controls
Cyber Security
Data Mining
Databases & DBA
Design Patterns & Practices
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
Expression Studio
F#
Files, Directory, IO
Games Programming
GDI+
General
Generative Engine Optimization (GEO)
Google Cloud
Google Development
Graphics Design
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Internet & Web
Internet of Things
Ionic
iOS
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
kotlin
Leadership
Learn .NET
LightSwitch
LINQ
Machine Learning
Microsoft 365
Microsoft Office
Microsoft Phone
Mobile Development
Multithreading
Nano Banana
NetBeans
Networking
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Power BI
Printing in C#
Products
Progressive Web Apps
Project Management
Python
Q#
QlikView
R
React
Reports using C#
Robotics & Hardware
Ruby on Rails
Salesforce
Security
Servers
SharePoint
SignalR
Silverlight
Smart Devices
Software Testing
SQL Language
SQL Server
Startups
String in C#
Swift
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
WCF
Wearables
Web Development
Web Services
Web3
Windows 10
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML Standard
XML
XNA
XSharp
Register
Login
2
Answers
Thread Headache
Thomas Sieverding
18y
3k
0
1
Active Directory
Reply
Ok so, the
program
I created needs to launch a variable amount of threads between 300-600 and be able to close individual threads/all threads at any time. Boolean checking is not an option - not all threads will close by the time new threads start and the program will not function. I'm looking for a way to give each thread an id and store it in an array parallel to variables_to_monitor so that the indexes match up and can be used to look up the id based on the index and terminate. Any ideas/help would be wonderful!!
private bool[] = new bool[0x301];
private Thread ThrScanner;
private int[] variables_to_monitor;
private int argument_to_pass;
private void timer1_Tick(object sender, EventArgs e)
{
for (int i = 0; i <= 0x300; i++)
{
if (variables_to_monitor[ i ] != 0 & !bool[ i ])
{
bool[ i ] = true;
arguement_to_pass = i;
ThrScanner = new Thread(Monitor);
ThrScanner.IsBackground = true;
ThrScanner.Start();
}
}
}
private void Monitor();
{
while (true)
{
int compare_variables = variables_to_monitor[arguement_to_pass];
while(compare_variables == variables_to_monitor)
{ System.Threading.Thread.Sleep(10); }
// variables changed, event triggered
}
}
private void button_Click(object sender,
System
.EventArgs e)
{
ThrScanner.Abort();
bool[] = new bool[0x301];
ThrScanner.Join();
}
Post
Reset
Cancel
Answers (
2
)
Related Discussion