private void Main_Load(object sender, EventArgs e) { //Se crea la instancia del recurso compartido Tenedores tenedores = new Tenedores(); //Se crean las instancia de los filósofos Filosofo filosofo0 = new Filosofo(0, tenedores, evento_CambioEstado); Filosofo filosofo1 = new Filosofo(1, tenedores, evento_CambioEstado); Filosofo filosofo2 = new Filosofo(2, tenedores, evento_CambioEstado); Filosofo filosofo3 = new Filosofo(3, tenedores, evento_CambioEstado); Filosofo filosofo4 = new Filosofo(4, tenedores, evento_CambioEstado); }
public Filosofo(int id, Tenedores tenedores, EventHandler manejadorEstado) { int numFilosofos = int.Parse(ConfigurationManager.AppSettings["NumFilosofos"]); this.tenedores = tenedores; this.id = id; ManejadorEstado = manejadorEstado; izquierda = id == 0 ? numFilosofos - 1 : id - 1; derecha = id; //Inicia la ejecucion del proceso Thread proceso = new Thread(new ThreadStart(Iniciar)); proceso.Start(); }