Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8250955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:04:49+00:00 2026-06-08T00:04:49+00:00

This is a simple .NET 4 application. Here’s the code I want to run:

  • 0

This is a simple .NET 4 application. Here’s the code I want to run:

string username = "userfoo";
string password = "passwordfoo";

for (int i = 0; i < 2000; i++)
{    
    uint matchId;
    if (!uint.TryParse(i.ToString(), out matchId))
    {
        Console.WriteLine("Invalid Match ID!");
        return;
    }

    Client client = new Client (username, password, matchId);

    // connect
    client.Connect();

    client.Wait();

    if (client.Match != null)
    {
        Console.WriteLine("Inserting match: #{0}", client.Match.match_id);
        Helpers.MatchHelper.AddMatchToDatabase(client.Match);
    }
    else
    {
        Console.WriteLine("Couldn't get match: #{0}", 1);
    }

}

Instead doing this one by one (it would take forever – 415 days nonstop according to my calculations), what’s the easiest way to invoke each iteration of this for loop asynchronously?

Most questions and articles are very old (circa 2001!) surely there must be a more modern approach?

http://msdn.microsoft.com/en-us/magazine/cc301332.aspx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:04:51+00:00Added an answer on June 8, 2026 at 12:04 am

    You can find information here: http://msdn.microsoft.com/en-us/library/ff963552.aspx. Basically, you just use Parallel.For(0, n, x => doSomething). That takes care of parallelization. This is a functionality of PLINQ that is extremely easy to use an in my experience works quite well.

    Your sample would look like this:

    string username = "userfoo";
    string password = "passwordfoo";
    
    Parallel.For(0, 2000, i =>
    {    
        uint matchId;
        if (!uint.TryParse(i.ToString(), out matchId))
        {
            Console.WriteLine("Invalid Match ID!");
            return;
        }
    
        Client client = new Client (username, password, matchId);
    
        // connect
        client.Connect();
    
        client.Wait();
    
        if (client.Match != null)
        {
            Console.WriteLine("Inserting match: #{0}", client.Match.match_id);
            Helpers.MatchHelper.AddMatchToDatabase(client.Match);
        }
        else
        {
            Console.WriteLine("Couldn't get match: #{0}", 1);
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Asp .net page like this simple one http://issamsoft.com/app2/page1.aspx and I want
Here is the simple scenario that I want to apply; There is a .NET
I have a simple Form-Based .NET application. In this I capture the FormClosing Event
Is there any way to keep this simple JQuery animation from flashing? http://jsfiddle.net/v3DVf/6/
This is a simple website in ASP.NET with C# using VS 2010. I have
I'm implementing a simple chat in .NET using Rx on the basis of this
I have an ajax form in asp.net mvc which is as simple as this:
I have a simple jquery flipcard animation - http://jsfiddle.net/gGAW5/36/ Now the way this flip
I have soft real-time .NET application run on W2008R2. I just realised that I
I developed a simple .net application that scrapes some data from web and saves

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.