Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fórum ➡ Parallel Threads ( The Funniest Version ) ♦
//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 // // This code has much fun. // If you'd rather have no fun, // see the other with less fun, // or even the other without fun. // THIS CODE COMPILES WITH *NO* WARNINGS ( AND NO ERRORS, OF COURSE ), JUST FOR MUCH FUN. namespace Rextester { using PT=Rextester.ParallelThread; class ParallelThread{ // *** NEEDED TO MAKE MUCH FUN *** public delegate PT ITSALLFUN(); // *** A NEW OPERATOR *** public static Action operator +(string s,PT p){ if(s!="ParallelThread")throw new Exception("!-- This task is NOT a ParallelThread one. --!"); if(_index>=Maximum)throw new Exception("!-- The index is too big. --!"); return actions[_index++]; } // *** MORE NEW OPERATORS *** public static bool operator <(PT p,int i){return PT._index<i;} public static bool operator >(PT p,int i){return PT._index>i;} // *** THE ACTIONS *** private static Action[] actions={ParallelThread0,ParallelThread1,ParallelThread2,ParallelThread3,ParallelThread4}; // *** MAXIMUM ACTIONS *** public static readonly int Maximum; // *** ACTIONS' INDEX AND ACCESSOR *** private static int _index; public int GetIndex(){return PT._index;} // *** THE STATIC CTOR *** /*ctor*/static ParallelThread(){ if((Maximum=actions.Length)==0)throw new Exception("!-- You forgot the actions to be taken. :) --!"); _index=0; } // *** 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",'-', 8,Thread.CurrentThread.ManagedThreadId);} public static void ParallelThread1(){Act("AND FOR LEARNING,",'+',16,Thread.CurrentThread.ManagedThreadId);} public static void ParallelThread2(){Act("WITH *GOOD* CODE!",'.',24,Thread.CurrentThread.ManagedThreadId);} public static void ParallelThread3(){Act("HAVE A GOOD TIME.",'*',32,Thread.CurrentThread.ManagedThreadId);} public static void ParallelThread4(){Act("HAHAHAHAHAHAHAHA!",':',40,Thread.CurrentThread.ManagedThreadId);} } class Program { public static void Main(string[] args) { Task[] tasks= new Task[PT.Maximum]; // *** SEE THE TYPE OF THE VARIABLE i, ITS DEFINITION AND USAGE *** for( PT.\u0049TS\u0041LL\u0046UN i=()=>new \u0050\u0054(); i()<tasks.Length; ){ tasks[-1+i().GetIndex()]= // *** SEE THE VARIABLE i: IT IS THE FOR LOOP'S ITERATION VARIABLE, JUST FOR MUCH FUN! :) *** Task.Run( "ParallelThread"+i() ); } Task.WaitAll(tasks); } } }
run
|
edit
|
history
|
help
0
work_laba#2
test
s
Testing list
aaaaa
Create id
Binary search tree - Post-order Traversal
project euler 10, C#
Captcha
Boo socks