Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

ThreadPoolHandler | ThreadPools made easy

Hey people,
So the other day I was in need of a multi-threaded application i.e. thread-pool. If you don't know what a thread-pool is, it's basically used mostly when you need to execute a single piece of code multiple times at the same time. Some situations would be, bot's, crawlers, brute-forcers, you name it.. Well if you have tried to use a thread-pool, you know that the MSDN example looks very dirty. And to be honest the whole concept is not that easy to grasp. So I implemented the whole thread-pool thing in my code the way MSDN shows and it ruined my "beautiful" looking code because of the way it works with the arrays. I sat down and recoded the whole concept in my way, but then an idea popped up, why not code a whole handler class that will help not only me, but the others. So here it is. The concept is, you declare a new handler and set the method as a delegate that has the code on it and then set the amount of threads you want to run that code in. When you hit start, it will start the threads and it has multiple events. First it has started, that will fire up whenever you start the process. Then there is stopped, it fires up whenever all of the threads finished working. Also there are stopped/started events for each thread. And there is also executed event, it will fire up whenever the code get's executed, this is useful with the loop function. When we are at the loop function, if you set the loop property to true, the method that you passed will be called on all threads until you call the stop method. This is useful for many things that you want to run until something is done. Keep in mind that if you call stop, all of the threads will finish their job and then stop, it will not force them to stop. Also if the loop property is not set to true, the stop method will do absolutely nothing. Every event has custom event args that has elapsed time info, threadid(the thread number in that pool), etc. Lastly there is the method IsRunning that will tell you if any of the threads are running. Another thing to note is that initially you must set the method to be executed, but you can change it later.

tl;dr: A class that hooks a method and executes it on multiple threads using a thread-pool. You also get status with multiple events.

Future ideas:
-Separate AppDomain
-Killable threads

Enough talking, here is the code:
http://pastebin.com/8Ry3VF4H

Example app(you can find the code in the source for this as well):
Spoiler (Click to View)
Code is pretty good man, good work. I wouldn't use it though since I OOP everything, so I handle my stuff differently. A lot of folk should still find this useful though
(Sep 20, 2014 10:45 AM)Cairns Wrote:  Code is pretty good man, good work. I wouldn't use it though since I OOP everything, so I handle my stuff differently. A lot of folk should still find this useful though

Thanks, but can you explain me what is not OOP here ?
Good thread/Tut, i told ya my opinion on some minor things already ^^
(Sep 20, 2014 11:45 AM)TheBarret Wrote:  Good thread/Tut, i told ya my opinion on some minor things already ^^

Ok I will try to not write walls of text in my future threads, jeez.
can i comment with out getting my head bit off???? You really need to learn how events should be used.
(Sep 20, 2014 02:37 PM)Sn0wX Wrote:  can i comment with out getting my head bit off???? You really need to learn how events should be used.

Lets hear it snow ^^ im listening mate
(Sep 20, 2014 03:15 PM)TheBarret Wrote:  Lets hear it snow ^^ im listening mate

why bother? if i point out badly written code i get told i am trolling. This whole thing is not how you use pools.
(Sep 20, 2014 03:24 PM)Sn0wX Wrote:  why bother? if i point out badly written code i get told i am trolling. This whole thing is not how you use pools.

How do you use events. I don't know. How do you use pools? I don't know. Can you please teach me ?
(Sep 20, 2014 03:37 PM)SIM-1456245 Wrote:  How do you use events. I don't know. How do you use pools? I don't know. Can you please teach me ?
Honest man, Snow can be mean but you must love him, anyways nice release i am hoping more from you, keep it up.
Thanks Electroalek!

@Snow - Could you not make your version of things, I would be also interested it in.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by CypicalOct 19, 2017 08:42 AM 12 405 Oct 19, 2017 08:42 AM
Last Post: gigajew
[.NET] by HyptonixMar 26, 2015 03:19 PM 3 117 Mar 26, 2015 03:19 PM
Last Post: Hyptonix
[.NET] by #MacklemoreJun 24, 2011 07:38 AM 0 50 Jun 24, 2011 07:38 AM
Last Post: #Macklemore