Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //token shared by animals
            SharedToken sharedToken = new SharedToken();

            animalList = new List<Animal>();
            threadList = new List<Thread>();

            animalList.Add(new Animal("frog.wav", sharedToken));
            animalList.Add(new Animal("duck.wav", sharedToken));
            animalList.Add(new Animal("meow.wav", sharedToken));

            for (int i = 0; i < animalList.Count; i++)
                threadList.Add(new Thread(animalList[i].speak));

            for (int i = 0; i < animalList.Count; i++){
                threadList[i].Start();

            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //token shared by animals
            SharedToken sharedToken = new SharedToken();

            animalList = new List <Animal>();
            threadList = new List <Thread>();

            animalList.Add(new Animal("frog.wav", sharedToken));
            animalList.Add(new Animal("duck.wav", sharedToken));
            animalList.Add(new Animal("meow.wav", sharedToken));

            for (int i = 0; i < animalList.Count; i++)
            {
                threadList.Add(new Thread(animalList[i].speak));
            }

            for (int i = 0; i < animalList.Count; i++)
            {
                threadList[i].Start();
            }
        }
Ejemplo n.º 3
0
 public Animal(String soundFileName, SharedToken sharedToken)
 {
     soundPlayer      = new SoundPlayer(soundFileName);
     this.sharedToken = sharedToken;
 }
Ejemplo n.º 4
0
 public Animal(String soundFileName, SharedToken sharedToken)
 {
     soundPlayer = new SoundPlayer(soundFileName);
     this.sharedToken = sharedToken;
 }