Created
December 23, 2014 17:14
-
-
Save neuecc/ac773bff6a38a3b7248e to your computer and use it in GitHub Desktop.
Parallel.StringBuilder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var result = new StringBuilder(); | |
Parallel.ForEach(Enumerable.Range(1, 1000000), () => new StringBuilder(), (x, option, sb) => | |
{ | |
sb.Append(x); | |
return sb; | |
}, sb => | |
{ | |
lock (result) | |
{ | |
result.Append(sb.ToString()); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment