![]() |
|
[.NET] For Loop / MultiThreading Off ComboBox Value? - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [.NET] For Loop / MultiThreading Off ComboBox Value? (/showthread.php?tid=5554749) |
For Loop / MultiThreading Off ComboBox Value? - Gørilla - Feb 18, 2017 I'm trying to implement a simple code but I want it to be threaded as many times as a combobox says. For example: Combo box value is: 25 This means the thread count is '25'. I want a certain piece of code to run 25 times off a listbox but not duplicate each item 25 times like it seems to do when I 'multi-thread' it. My idea for a code: Code for i as integer = 1 to combobox1.valueBut how do I get this above code to run the combo box value into threads? My code I'm trying to get multithreaded by the combobox value: Code Private Sub Checker()(this is just a sample code and will not be used in my project). I can't seem to figure out in my head how to make the two work off each other... Ninja tried helping me, but I don't want to mooch off his quality skill. Thanks for the help! * - Ninja - Feb 18, 2017 So what is the problem with this code? Does it give an error? * - jujuger - Feb 18, 2017 Happy to help, but need more info. Do you want to run Checker() on a separate thread from the GUI-Main thread? Is that what you are saying? Use async maybe? Reply with more details * - Gørilla - Feb 18, 2017 I have fixed up the code to where it will run on it's own fairly quickly (based on thread count according to the combo box's value.) But I'm having the issue to where it will check the same listbox item over and over until the threads are done, then move onto the next. So if I set my thread count to 25 it will check the same listbox item 25 times before moving to the next item. Is there maybe a way to check if it's being used already? My code : Code 'Start Checker Thread* - Ninja - Feb 19, 2017 What you should do is either write a class that distributes the workload over the threads, but that might be too complicated for you. Or you can put a for loop inside the checker sub and have an integer for the index as a parameter and start the loop at that number, and increment with that number. So something like this: Code Do While (i <= threadcount)* - xxdarklord65xx - Feb 19, 2017 (Feb 18, 2017 03:19 PM)Gørilla Wrote: I have fixed up the code to where it will run on it's own fairly quickly (based on thread count according to the combo box's value.)i have tried to do it . its really complicated . i know what did u mean . specially in brute force . like i was trying to make it 90 threads to finish the list so fast . but not like 90 threads on the same thing ..So what i did is that i made my http web request more faster using some techniques for example : Code 'InCrease And Control Speed* - Closed User - Feb 19, 2017 I would advice you to look into Parallel programming :) * - Cairns - Feb 19, 2017 Your problem is you're running the same method over and over. You are going to have to be smarter about this when it comes to multi threading * - xxdarklord65xx - Feb 19, 2017 (Feb 19, 2017 05:30 AM)Big Benim Wrote: I would advice you to look into Parallel programming :) true . its all about the parallel threading . * - Ninja - Feb 19, 2017 If you want you can use the Partitioner class to partition a collection into an amount of IEnumerators and then use a while loop to loop over the proxies. * - Gørilla - Feb 19, 2017 Ninja helped me find my problem which is my start checker sub is looped. But if I remove my loop, I have to remove my do while. So if I were to remove the do while, would I just write it out plain without any 'do' statements? I'm also a beginner in multithreading and this is just to help me learn. If I try to just write it out with i <= threadcount it throws a syntax error on i . I feel like I'm so close! Now I'm having an issue where a variable is being hidden in a block or something.. Screenshot: https://gyazo.com/85c539d4dd1489d083415df82a518ee8 Anyone else able to help me? I really need it! * - Decim - Feb 20, 2017 (Feb 19, 2017 12:53 PM)Gørilla Wrote: Ninja helped me find my problem which is my start checker sub is looped. But if I remove my loop, I have to remove my do while. So if I were to remove the do while, would I just write it out plain without any 'do' statements? I'm also a beginner in multithreading and this is just to help me learn. You're declaring the variable 'i' twice. ? ? * - Closed User - Feb 20, 2017 (Feb 19, 2017 12:53 PM)Gørilla Wrote: Ninja helped me find my problem which is my start checker sub is looped. But if I remove my loop, I have to remove my do while. So if I were to remove the do while, would I just write it out plain without any 'do' statements? I'm also a beginner in multithreading and this is just to help me learn. PARALLEL PROGRAMMING YA MONKEY! On the real, look into parallel threading and you won't ever have those issues * - Gørilla - Feb 20, 2017 Ok, I'll look into it. Thanks for the help guys! |