{"id":20605174,"url":"https://github.com/arnab-developer/maxdegreeofparallelism","last_synced_at":"2025-07-27T22:35:40.204Z","repository":{"id":68915300,"uuid":"370028365","full_name":"Arnab-Developer/MaxDegreeOfParallelism","owner":"Arnab-Developer","description":"Max degree of parallelism with Parallel.ForEach() method","archived":false,"fork":false,"pushed_at":"2021-05-23T11:17:18.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-17T02:24:16.996Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Arnab-Developer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-23T10:58:11.000Z","updated_at":"2021-12-05T05:48:17.000Z","dependencies_parsed_at":"2023-03-24T11:20:20.154Z","dependency_job_id":null,"html_url":"https://github.com/Arnab-Developer/MaxDegreeOfParallelism","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arnab-Developer%2FMaxDegreeOfParallelism","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arnab-Developer%2FMaxDegreeOfParallelism/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arnab-Developer%2FMaxDegreeOfParallelism/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arnab-Developer%2FMaxDegreeOfParallelism/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Arnab-Developer","download_url":"https://codeload.github.com/Arnab-Developer/MaxDegreeOfParallelism/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242250932,"owners_count":20096895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T09:26:57.253Z","updated_at":"2025-03-06T16:54:47.966Z","avatar_url":"https://github.com/Arnab-Developer.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Max degree of parallelism\n\nA demo to take input from user and use that as max degree of parallelism\nwith `Parallel.ForEach()` method.\n\n`Parallel.ForEach()` method can process items in a collection in multiple\nthreads parallelly but we can specify the max number of parallel threads\nin that.\n\nOne of the overload of `Parallel.ForEach()`\n\n``` csharp\npublic static ParallelLoopResult ForEach\u003cTSource\u003e(\n    IEnumerable\u003cTSource\u003e source, ParallelOptions parallelOptions, Action\u003cTSource\u003e body);\n```\n\nUsage\n\n``` csharp\nParallel.ForEach(\n    students,\n    new ParallelOptions() { MaxDegreeOfParallelism = 2 },\n    student =\u003e\n    {\n        Console.WriteLine($\"Id: {student.Id}, Name: {student.FirstName} {student.LastName}\");\n        Thread.Sleep(2000);\n    });\n```\n\n## Output\n\n```\n---- PrintSingleThread\nThread id: 1, Id: 1, Name: f1 l1\nThread id: 1, Id: 2, Name: f2 l2\nThread id: 1, Id: 3, Name: f3 l3\nThread id: 1, Id: 4, Name: f4 l4\nThread id: 1, Id: 5, Name: f5 l5\nThread id: 1, Id: 6, Name: f6 l6\nThread id: 1, Id: 7, Name: f7 l7\nThread id: 1, Id: 8, Name: f8 l8\nThread id: 1, Id: 9, Name: f9 l9\nThread id: 1, Id: 10, Name: f10 l10\nTime took: 20 sec\n\n---- PrintMultiThread\nThread id: 1, Id: 1, Name: f1 l1\nThread id: 4, Id: 6, Name: f6 l6\nThread id: 5, Id: 2, Name: f2 l2\nThread id: 6, Id: 7, Name: f7 l7\nThread id: 1, Id: 3, Name: f3 l3\nThread id: 7, Id: 5, Name: f5 l5\nThread id: 4, Id: 8, Name: f8 l8\nThread id: 5, Id: 10, Name: f10 l10\nThread id: 1, Id: 4, Name: f4 l4\nThread id: 4, Id: 9, Name: f9 l9\nTime took: 6 sec\n\nProvide max degree of parallelism value: 2\n\n---- PrintMultiThreadWithMaxDegreeOfParallelism\nThread id: 4, Id: 1, Name: f1 l1\nThread id: 1, Id: 6, Name: f6 l6\nThread id: 1, Id: 7, Name: f7 l7\nThread id: 5, Id: 2, Name: f2 l2\nThread id: 1, Id: 8, Name: f8 l8\nThread id: 5, Id: 3, Name: f3 l3\nThread id: 1, Id: 9, Name: f9 l9\nThread id: 5, Id: 4, Name: f4 l4\nThread id: 1, Id: 10, Name: f10 l10\nThread id: 5, Id: 5, Name: f5 l5\nTime took: 10 sec\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnab-developer%2Fmaxdegreeofparallelism","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farnab-developer%2Fmaxdegreeofparallelism","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnab-developer%2Fmaxdegreeofparallelism/lists"}