Ciao a tutti! mi sono trovato a dover affrontare questa problematica... Spiego brevemente:
sono in un ciclo di gioco, e ho bisogno di far girare delle sequenze di filmati. Ho trovato il modo di gestirle ottimalmente con la classe Semaphore, ma appena ho creato più di 2 thread la sitazione è diventata fastidiosa... Come scritto nella MSDN il semaforo non esegue thread con una sequenza, va a caso! Però ho bisogno di una sequenza... Come faccio?
Premetto che mi serve un semaforo perchè devo gestire più thread... E mi servono i thread perchè mi serve captare l'input del joystick!
Questo è lo scheletro del codice. Grazie in anticipo
public static Semaphore Semaforo = new Semaphore(0, 1);
public static void Scena1()
{
Thread t1=new Thread(new ThreadStart(Frame1));
t1.Start();
Thread t2 = new Thread(new ThreadStart(Frame2));
t2.Start();
Thread t3 = new Thread(new ThreadStart(Frame3));
t3.Start();
Thread t4 = new Thread(new ThreadStart(Frame4));
t4.Start();
Semaforo.Release(1);
}
public static void Frame1()
{
Semaforo.WaitOne();
//codice
Semaforo.Release();
}
public static void Frame2()
{
Semaforo.WaitOne();
//codice
Semaforo.Release();
}
public static void Frame3()
{
Semaforo.WaitOne();
//codice
Semaforo.Release();
}
public static void Frame4()
{
Semaforo.WaitOne();
//codice
Semaforo.Release();
}