Jump to content
UBot Underground

Cancelling Out Of Multithreading Before It Finishes


Recommended Posts

Hi there,

 

I have multithreading working well in my bot, but I'm trying to enhance the functionality to allow for a user to cancel the process before the multithreading completes and having some issues.

 

This is some code from the multithreaded proxy checker part of the bot, as it's the most simple threading, and wanted to get it working first before trying to implement the same enhancements on the main bot process.

 

Approach #1: First i tried changing it from looping through the number of proxies to check to using a loop while #cancelProxyTesting = false, and added a button that sets #cancelProxyTesting to true when clicked. That stopped the proxy testing, but no matter how many threads it was supposed to run, it only ran one thread at a time and after experimenting quite a bit I have no idea why.

 

Approach #2 (Code below): I changed the loop total back to the proxy total, and set a check for #cancelProxyTesting inside the main work - if set to true (by user clicking the button) it would return blank, and the code was supposed to set the live thread count back to 0 and update the UI. Clicking the stop button does seem to stop the testing, but the live thread count stays above 0 and the UI never updates (the last 3 lines of code in the sample below). Also, sometimes when the stop button is clicked it starts throwing a bunch of errors over and over, the main one I remember is index out of range, which is odd because I never get that error when using the code without the stopTesting check in place.

 

Anyways, sample code is below, can anyone see how I might be able to effectively achieve cancelling multithreading gracefully when the user requests it? If you'd rather post clean different code that shows the same result, that would be amazing too, whatever is easiest.

 

Thanks in advance for your time.

 

define testProxies {
                plugin command("XAMLUI.dll", "xaml control state", "btnCancelProxyTest", "Visible", "True")
                set(#liveThreads,0,"Global")
                set(#proxyTestMode,$table cell(&proxiesToTest,0,1),"Global")
                remove from list(%proxiesToTest,0)
                plugin command("TableCommands.dll", "delete from table", &proxiesToTest, "Row", 0)
                clear list(%proxyTestCountList)
                set(#proxyTotal,$list total(%proxiesToTest),"Global")
                set(#proxyTestCountListCurrent,0,"Global")
                loop while($comparison(#proxyTestCountListCurrent,"< Less than",#proxyTotal)) {
                    add item to list(%proxyTestCountList,#proxyTestCountListCurrent,"Don\'t Delete","Global")
                    increment(#proxyTestCountListCurrent)
                }
                set(#cancelProxyTesting,$false,"Global")
                loop(#proxyTotal) {
                    loop while($comparison(#liveThreads,"=",#maxThreadCount)) {
                        wait(1)
                    }
                    increment(#liveThreads)
                    thread {
                        plugin command("LocalDictionary.dll", "init local dictionary")
                        plugin command("HTTP post.dll", "http auto redirect", "Yes")
                        plugin command("HTTP post.dll", "http max redirects", 10)
                        if(#cancelProxyTesting) {
                            then {
                                return("")
                                set(#liveThreads,0,"Global")
                            }
                            else {
                                checkProxies()
                            }
                        }
                        decrement(#liveThreads)
                        increment(#count)
                    }
                }
                loop while($comparison(#liveThreads,"!=",0)) {
                    wait(1)
                }
                plugin command("XAMLUI.dll", "xaml control state", "btnCancelProxyTest", "Visible", "False")
                set(#proxiesToTest,$nothing,"Global")
                plugin command("XAMLUI.dll", "xaml control value set", "txtNewProxies", $nothing)
            }
        }

Edited by drewness
Link to post
Share on other sites
  • 3 weeks later...

The big caution I offer is be careful when initiating threads. Knowing what I know in C# and threading, you can run into real issues if you create thousands of threads.

 

Frank

Link to post
Share on other sites

Hi Frank, thanks for the response. I'm pretty familiar with threading in C#, I have my bots limited to 50 threads right now and they're all running like champs, preciate the tip though, definitely good to keep in mind!

 

Sent from my SAMSUNG-SM-N920A using Tapatalk

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...