foreach as parallel c#
C#
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Drawing;
public class Example
{
public static void Main()
{
// A simple source for demonstration purposes. Modify this path as necessary.
string[] files = Directory.GetFiles(@"C:\Users\Public\Pictures\Sample Pictures", "*.jpg");
string newDir = @"C:\Users\Public\Pictures\Sample Pictures\Modified";
Directory.CreateDirectory(newDir);
// Method signature: Parallel.ForEach(IEnumerable<TSource> source, Action<TSource> body)
Parallel.ForEach(files, (currentFile) =>
{
// The more computational work you do here, the greater
// the speedup compared to a sequential foreach loop.
string filename = Path.GetFileName(currentFile);
var bitmap = new Bitmap(currentFile);
bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);
bitmap.Save(Path.Combine(newDir, filename));
// Peek behind the scenes to see how work is parallelized.
// But be aware: Thread contention for the Console slows down parallel loops!!!
Console.WriteLine($"Processing {filename} on thread {Thread.CurrentThread.ManagedThreadId}");
//close lambda expression and method invocation
});
// Keep the console window open in debug mode.
Console.WriteLine("Processing complete. Press any key to exit.");
Console.ReadKey();
}
}
Also in C#:
- Title
- c# param exception
- Category
- C#
- Title
- converting letter to ascii
- Category
- C#
- Title
- how to make rb.addforce 2d
- Category
- C#
- Title
- find gameobject with tag
- Category
- C#
- Title
- add getenumerator to class c#
- Category
- C#
- Title
- how to create a variable in C#
- Category
- C#
- Title
- Check object is in layermask unity
- Category
- C#
- Title
- c# two dimensional array
- Category
- C#
- Title
- how to add a gameobject
- Category
- C#
- Title
- asp.net core 3.1: cast jObject to dictionary<string,string>
- Category
- C#
- Title
- how to get array of children transform
- Category
- C#
- Title
- unity make a int arry with preset values
- Category
- C#
- Title
- check if number is even or odd c#
- Category
- C#
- Title
- no overload for 'useItemOnSceneLoad' matches delegate 'UnityAction<Scene, LoadSceneMode>'
- Category
- C#
- Title
- c# sort list
- Category
- C#
- Title
- c list add element
- Category
- C#
- Title
- internal c#
- Category
- C#
- Title
- unity set text value
- Category
- C#
- Title
- c# webcam
- Category
- C#
- Title
- draw sphere cast unity with program
- Category
- C#
- Title
- c# stringbuilder
- Category
- C#
- Title
- unity lerp
- Category
- C#
- Title
- native-googlesignin configuration is null!?
- Category
- C#
- Title
- unity get max occurrence in list
- Category
- C#
- Title
- c# change colour of console
- Category
- C#
- Title
- how to reference function in unity
- Category
- C#
- Title
- how to set a transform equal to something unity
- Category
- C#
- Title
- c# split large file into chunks
- Category
- C#
- Title
- foreach c#
- Category
- C#
- Title
- string format c#
- Category
- C#
- Title
- c# changimg to one decimal place
- Category
- C#
- Title
- unity3d raycast
- Category
- C#
- Title
- grab reference from method parameter c#
- Category
- C#
- Title
- c# get desktop path
- Category
- C#
- Title
- the request was aborted could not create ssl/tls secure channel. c# restsharp
- Category
- C#
- Title
- c# empty array
- Category
- C#
- Title
- unity connect to firebase
- Category
- C#
- Title
- unity array c#
- Category
- C#
- Title
- c# getter setter
- Category
- C#
- Title
- c# bitmap to picturebox
- Category
- C#
- Title
- reverse string c#
- Category
- C#
- Title
- c#if
- Category
- C#
- Title
- unity check tag
- Category
- C#
- Title
- how to make an array in csharp
- Category
- C#
- Title
- unity up arrow input
- Category
- C#
- Title
- c# cancellationtoken
- Category
- C#
- Title
- convert string to decimal c#
- Category
- C#
- Title
- c# loop through list
- Category
- C#
- Title
- c# list to string join
- Category
- C#
- Title
- c# remove first 5 characters from string
- Category
- C#
- Title
- c# listview
- Category
- C#
- Title
- dont destroy on load unity
- Category
- C#
- Title
- c# clear console read chache
- Category
- C#
- Title
- array syntax c#
- Category
- C#
- Title
- print gridcontrol devexpress
- Category
- C#
- Title
- how to find the area of a circle
- Category
- C#
- Title
- c# how to refreshyour bindingsource
- Category
- C#
- Title
- .sh script: check if file exist
- Category
- C#
- Title
- instantiate object in circle
- Category
- C#
- Title
- asp net identity add a unique fields to user
- Category
- C#
- Title
- c# size of enum
- Category
- C#
- Title
- get day month year from date c#
- Category
- C#
- Title
- double tryparse dot comma
- Category
- C#
- Title
- how to destroy a gameobject after some hits in unity 3d
- Category
- C#
- Title
- add text to combobox c#
- Category
- C#
- Title
- verifyusertokenasync password reset token
- Category
- C#
- Title
- how to instantiate a gameobject
- Category
- C#
- Title
- how to convert a number to 2 decimal places in c#
- Category
- C#
- Title
- how to hide a panel ui unity
- Category
- C#
- Title
- c# EncoderParameter
- Category
- C#
- Title
- c# new list object
- Category
- C#
- Title
- C# how to expose an internal class to another project in the solution
- Category
- C#
- Title
- c sharp add item to dictionary
- Category
- C#
- Title
- how to use variables in c#
- Category
- C#
- Title
- Linq - Random Elements
- Category
- C#
- Title
- how to select time and date in datetimepicker in c#
- Category
- C#
- Title
- for each textbox c#
- Category
- C#
- Title
- same click event diffrenet buttonms c#
- Category
- C#
- Title
- nunit return parameter
- Category
- C#
- Title
- Add component object to gameobject unity
- Category
- C#
- Title
- open zip file in c#
- Category
- C#
- Title
- MVC company assignments
- Category
- C#
- Title
- unity quaternion identity
- Category
- C#
- Title
- how to hide and show object in unity script
- Category
- C#
- Title
- c# round to closest multiple
- Category
- C#
- Title
- asp.net c# write string to text file
- Category
- C#
- Title
- unity how to change max fps
- Category
- C#
- Title
- how to create a list in c# unity
- Category
- C#
- Title
- bundle.config in mvc is missing
- Category
- C#
- Title
- c# exit for
- Category
- C#
- Title
- c# authorize attribute
- Category
- C#
- Title
- move file from one folder to another c#
- Category
- C#
- Title
- import regex c#
- Category
- C#
- Title
- c# check if string is all numbers
- Category
- C#
- Title
- random from list c#
- Category
- C#
- Title
- invalidoperationexception c# ui thread
- Category
- C#
- Title
- download file from url asp net web api c#
- Category
- C#
- Title
- C# enum
- Category
- C#
- Title
- vector3.lerp
- Category
- C#
- Title
- print content of array c#
- Category
- C#