Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fórum Parallel Threads ( Without Fun )
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Threading; // aljodav // http://rextester.com/users/376 // // There's no fun in this code: it is serious. // So, see the other with much fun namespace Rextester { using P=Rextester.ParallelThread; static class ParallelThread{ // *** THE VERY HANDY ACTION *** public static Action<string,char,int,int> Act=(s,r,q,d)=>{ Array.ForEach(s.ToCharArray(),c=>{ Task.Delay(Environment.TickCount+d&127); Console.WriteLine("{0} {1}",new string(r,q),c); }); }; // *** THE ACTIONS' IMPLEMENTATIONS *** public static void ParallelThread0(){Act("JUST FOR MUCH FUN",'-',16,Thread.CurrentThread.ManagedThreadId);} public static void ParallelThread1(){Act("AND FOR LEARNING,",'+',32,Thread.CurrentThread.ManagedThreadId);} public static void ParallelThread2(){Act("WITH *GOOD* CODE!",'.',48,Thread.CurrentThread.ManagedThreadId);} } class Program { public static void Main(string[] args) { Action[] actions={P.ParallelThread0,P.ParallelThread1,P.ParallelThread2}; Task[] tasks= new Task[actions.Length]; int j=-1; Array.ForEach(actions,a=>tasks[++j]=Task.Run(a)); Task.WaitAll(tasks); } } }
run
|
edit
|
history
|
help
0
ReplaceNotExpectedCharacters
example
Readonly
3. Delegates and events
c# problem
basics of generics
Enumerable expansion
Override method/function in C#
R
minimal path for triangle