![]() |
|
[C#] Parallelize HttpWebRequest [Really Hard C#] - 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: [C#] Parallelize HttpWebRequest [Really Hard C#] (/showthread.php?tid=5857820) Pages: Pages
1
2
|
Parallelize HttpWebRequest [Really Hard C#] - FryPan - Jul 4, 2018 Hi there, What I'm trying to do:
Account.cs: ![]() myId is my own ID (not needed in send message method). authToken is used to login (not needed in send message method). HttpMethods.cs: ![]() realId above is the ID of a person to message. If anyone can solve this one for me, I'm even willing to reward. This shit is frying my brain. 🤝 RE: Parallelize HttpWebRequest [Really Hard C#] - Washi - Jul 4, 2018 (Jul 4, 2018 11:39 AM)FryPan Wrote: If anyone can solve this one for me, I'm even willing to reward. This shit is frying my brain. 🤝 Solve what exactly? You did not specify the problem that you are having? RE: Parallelize HttpWebRequest [Really Hard C#] - Charger - Jul 4, 2018 Read up on Multi Threading (example) RE: Parallelize HttpWebRequest [Really Hard C#] - FryPan - Jul 4, 2018 (Jul 4, 2018 11:45 AM)Charger Wrote: Read up on Multi Threading (example) Yes, I know about multi threading, but I'm asking on help to set it up: IE: Parallel.For the account instances, and then normal loop through the TXT realIDs? (Jul 4, 2018 11:43 AM)Washi Wrote: Solve what exactly? You did not specify the problem that you are having? Sorry for not making it clear. I'm trying to:
RE: Parallelize HttpWebRequest [Really Hard C#] - Charger - Jul 4, 2018 (Jul 4, 2018 11:46 AM)FryPan Wrote: Yes, I know about multi threading, but I'm asking on help to set it up:You can't fire 1000 requests at the same time. Your computer can't handle it nor can the server. What you are trying to do is what multi threading does. RE: Parallelize HttpWebRequest [Really Hard C#] - Zettabit - Jul 4, 2018 Also, directly supplying the ‘message’ into your preset JSON will break if the message is not in proper format. I would also add some sort of response checking to make sure the server returned that the message was sent successfully. RE: Parallelize HttpWebRequest [Really Hard C#] - Tommy Chong- - Jul 4, 2018 Multithreading is exactly what you need. I used the threadpool for a similar purpose. https://www.dotnetperls.com/threadpool Code for (int i = 0; i < _maxThreads; i++)RE: Parallelize HttpWebRequest [Really Hard C#] - FryPan - Jul 4, 2018 (Jul 4, 2018 01:42 PM)Tommy Chong- Wrote: Multithreading is exactly what you need. Thanks for the only message on topic. Any chance you know of an example that is similar but uses tasks? (Jul 4, 2018 11:49 AM)Charger Wrote: You can't fire 1000 requests at the same time. Your computer can't handle it nor can the server. You read the thread wrong RE: Parallelize HttpWebRequest [Really Hard C#] - Tommy Chong- - Jul 4, 2018 (Jul 4, 2018 02:01 PM)FryPan Wrote: Thanks for the only message on topic. Any chance you know of an example that is similar but uses tasks? Is there any reason why you want to use tasks over threadpool? RE: Parallelize HttpWebRequest [Really Hard C#] - alexconnolly - Jul 5, 2018 More control over a task than a thread pool. Thread pool is like a magic invisible wall kinda like a glory hole where you just shove shit in and you see what happens. Tasks allows more control over this shit and is non-glory hole version. A good read is here for OP wanting to use tasks: docs.microsoft.com/en-us/dotnet/standard/parallel-programming/task-based-asynchronous-programming RE: Parallelize HttpWebRequest [Really Hard C#] - FryPan - Jul 5, 2018 (Jul 5, 2018 03:44 AM)alexconnolly Wrote: More control over a task than a thread pool. Thanks bud. Nice analogy lmao. RE: Parallelize HttpWebRequest [Really Hard C#] - Tommy Chong- - Jul 5, 2018 (Jul 5, 2018 03:44 AM)alexconnolly Wrote: More control over a task than a thread pool. You are right about this, but for the simple tasks OP need to perform, the threadpool should be sufficient enough RE: Parallelize HttpWebRequest [Really Hard C#] - FryPan - Jul 5, 2018 (Jul 5, 2018 10:10 AM)Tommy Chong- Wrote: You are right about this, but for the simple tasks OP need to perform, the threadpool should be sufficient enough I'm going to be using Parallel.For & then a normal loop in that one. RE: Parallelize HttpWebRequest [Really Hard C#] - Closed User - Jul 5, 2018 Definitely tasks, people mentioning threadpool should get lynched. Tasks provides more control, way easier debugging and cleaner code EDIT: If you use async that is, if you don't use async might aswell use backgroundworker lol RE: Parallelize HttpWebRequest [Really Hard C#] - flAmingw0rm - Jul 5, 2018 You can also look up SemaphoreSlim. It allows you to control the maximum amount of tasks you can run in parallel. |