Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



   1283

[C#] Need help aborting threads and stopping checker

by Visible - 03 June, 2020 - 03:01 AM
This post is by a banned member (Visible) - Unhide
Visible  
Registered
29
Posts
4
Threads
5 Years of service
#1
(This post was last modified: 03 June, 2020 - 03:04 AM by Visible.)
This is the code to start all the threads for my checker:
Code:
        public void Run()
        {
            Task.Run(() =>
            {
                this.Invoke(new MethodInvoker(delegate ()
                {
                    bStart.Enabled = false;
                }));

                for (int i = 1; GlobalVariables.ThreadCount > i; i++)
                {
                    Thread T = new Thread(DoWork)
                    {
                        IsBackground = true
                    };

                    GlobalVariables.TList.Add(T);
                    GlobalVariables.TList[i-1].Start();

                    Thread.Sleep(20);
                }
                this.Invoke(new MethodInvoker(delegate ()
                {
                    bStart.Enabled = true;
                }));
            });
        }

This is the code to abort all the threads and stop the checker:
Code:
        private void Stop()
        {
            GlobalVariables.Running = false;

            foreach (Thread T in GlobalVariables.TList)
            {
                T.Abort();
            }

            foreach (string Combo in GlobalVariables.TempQueue)
            {
                GlobalVariables.ComboQueue.Enqueue(Combo);
            }

            GlobalVariables.TempQueue.Clear();
            GlobalVariables.TList.Clear();
        }
The code to start all the threads works fine, however when I want to stop the checker, it freezes the UI and sometimes throws errors. Can someone show me a more efficient way of doing this please?
This post is by a banned member (Sango) - Unhide
Sango  
Heaven
4.659
Posts
1.085
Threads
6 Years of service
#2
use python and I'll help you :P
This post is by a banned member (PartyGhost) - Unhide
965
Posts
143
Threads
6 Years of service
#3
OMG I FOUND THE BEST WAY TO SOLVE THIS ERROR WORKS IN EVERY LANGUAGE AND OS CHECK IT OUT HERE:

Unplug power cord -> wait 5 mins -> Plug back in
↓↓↓ Click these to make sure it's me ↓↓↓
Signal
This post is by a banned member (Visible) - Unhide
Visible  
Registered
29
Posts
4
Threads
5 Years of service
#4
(03 June, 2020 - 03:41 AM)PartyGhost Wrote: Show More
OMG I FOUND THE BEST WAY TO SOLVE THIS ERROR WORKS IN EVERY LANGUAGE AND OS CHECK IT OUT HERE:

Unplug power cord -> wait 5 mins -> Plug back in

I don't think this would help, I think it really has to do something with my code and not my actual PC. My code works but it's like every single time that I stop the checker, stuff begins to mess up. I think it might be the fact that I used a 'List<Thread>'. Besides, unplugging the power cord while the computer is still running seems like a bad idea, and if the computer is already off and then you unplug the power cord, i feel like it wouldn't do anything useful since the computer is already off. Please help.
This post is by a banned member (Xaxlii) - Unhide
Xaxlii  
Supreme
126
Posts
55
Threads
5 Years of service
#5
Depending on what type of threading your using but usually i would do the following:
Code:
thread.Abort();
wack
This post is by a banned member (Visible) - Unhide
Visible  
Registered
29
Posts
4
Threads
5 Years of service
#6
This is a bump
This post is by a banned member (zoony) - Unhide

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)