DO NOT DEAL WITH THIS MEMBER
Jul 4, 2018 11:39 AM
(This post was last modified: Jul 4, 2018 11:42 AM by FryPan.)
Hi there,
What I'm trying to do:
- I log into a bunch of accounts (instances of Account.cs) on the program.
- Each account is set a TXT of people (realIds) to message.
- They all do it at the same time.
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. 🤝
(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?
Read up on Multi Threading ( example)
DO NOT DEAL WITH THIS MEMBER
Jul 4, 2018 11:46 AM
(This post was last modified: Jul 4, 2018 11:47 AM by FryPan.)
(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:
- Import a bunch of accounts ( Account acc = new Account("user", "pass") )
- Assign a txt of realIDs/Accounts to message (contains 1000 users)
- They all do it at the same time.
(Jul 4, 2018 11:46 AM)FryPan Wrote: 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?
Sorry for not making it clear. I'm trying to:
- Import a bunch of accounts ( Account acc = new Account("user", "pass") )
- Assign a txt of realIDs/Accounts to message (contains 1000 users)
- They all do it at the same time.
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.
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.
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++)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(Worker), i);
}
private void Worker(object state)
{
// call your method that does the HTTP requests
}
DO NOT DEAL WITH THIS MEMBER
Jul 4, 2018 02:01 PM
(This post was last modified: Jul 4, 2018 02:02 PM by FryPan.)
(Jul 4, 2018 01:42 PM)Tommy Chong- Wrote: 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++)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(Worker), i);
}
private void Worker(object state)
{
// call your method that does the HTTP requests
}
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.
What you are trying to do is what multi threading does.
You read the thread wrong
(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?
You read the thread wrong
Is there any reason why you want to use tasks over threadpool?
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
DO NOT DEAL WITH THIS MEMBER
(Jul 5, 2018 03:44 AM)alexconnolly Wrote: 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
Thanks bud. Nice analogy lmao.
(Jul 5, 2018 03:44 AM)alexconnolly Wrote: 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
You are right about this, but for the simple tasks OP need to perform, the threadpool should be sufficient enough
DO NOT DEAL WITH THIS MEMBER
(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.
DO NOT DEAL WITH THIS MEMBER
Jul 5, 2018 02:52 PM
(This post was last modified: Jul 5, 2018 02:53 PM by Closed User.)
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
You can also look up SemaphoreSlim. It allows you to control the maximum amount of tasks you can run in parallel.
|