Created
May 6, 2014 10:47
-
-
Save anonymous/906ab1fc1323b09c3187 to your computer and use it in GitHub Desktop.
base
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; | |
using System.Threading; | |
using System.Collections.Generic; | |
public class Animal{ | |
public string Name; | |
} | |
public class Panda: Animal | |
{ | |
public void Chew() | |
{ | |
Console.WriteLine(String.Format("{0}: Nama-nama!", Name)); | |
} | |
public void Sleap() | |
{ | |
Console.WriteLine(String.Format("{0}: Z-z-z!", Name)); | |
} | |
public void Live() | |
{ | |
for (var i = 0; i < 50; ++i) | |
{ | |
Sleap(); | |
Thread.Sleep(100); | |
Chew(); | |
} | |
} | |
} | |
public class Park | |
{ | |
private readonly List<Panda> pandas = new List<Panda>(); | |
private readonly List<Thread> threads = new List<Thread>(); | |
public Park() | |
{ | |
for(var i = 0; i < 99; ++i) { | |
pandas.Add(new Panda() | |
{ | |
Name = i.ToString() | |
}); | |
} | |
pandas.ForEach( | |
panda => { | |
var t = new Thread(() => panda.Live()); | |
threads.Add(t); | |
t.Start(); | |
}); | |
} | |
} | |
namespace ThreadingExamples | |
{ | |
static class Programm | |
{ | |
static void Main() | |
{ | |
var p = new Park(); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment