Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Concurrent-computing/C-sharp/concurrent-computing-1.cs
Normal file
21
Task/Concurrent-computing/C-sharp/concurrent-computing-1.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
static Random tRand = new Random();
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Thread t = new Thread(new ParameterizedThreadStart(WriteText));
|
||||
t.Start("Enjoy");
|
||||
|
||||
t = new Thread(new ParameterizedThreadStart(WriteText));
|
||||
t.Start("Rosetta");
|
||||
|
||||
t = new Thread(new ParameterizedThreadStart(WriteText));
|
||||
t.Start("Code");
|
||||
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
private static void WriteText(object p)
|
||||
{
|
||||
Thread.Sleep(tRand.Next(1000, 4000));
|
||||
Console.WriteLine(p);
|
||||
}
|
||||
13
Task/Concurrent-computing/C-sharp/concurrent-computing-2.cs
Normal file
13
Task/Concurrent-computing/C-sharp/concurrent-computing-2.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class Program
|
||||
{
|
||||
static async Task Main() {
|
||||
Task t1 = Task.Run(() => Console.WriteLine("Enjoy"));
|
||||
Task t2 = Task.Run(() => Console.WriteLine("Rosetta"));
|
||||
Task t3 = Task.Run(() => Console.WriteLine("Code"));
|
||||
|
||||
await Task.WhenAll(t1, t2, t3);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class Program
|
||||
{
|
||||
static void Main() => Parallel.ForEach(new[] {"Enjoy", "Rosetta", "Code"}, s => Console.WriteLine(s));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue