HTML կոդ:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace AGamer.Gamer
{
public sealed class GenericGamer<TConnector,TGamer>
where TConnector : IConnector
where TGamer : Gamer
{
private TConnector connector_;
private TGamer gamer_;
private bool exit_;
private AutoResetEvent waitForOutput = new AutoResetEvent(false);
private AutoResetEvent waitForInput = new AutoResetEvent(false);
public GenericGamer(TConnector connector, TGamer gamer)
{
connector_ = connector;
gamer_ = gamer;
}
public void Run()
{
Thread inputThread = new Thread(new ThreadStart(InputThreadFunction));
Thread outputThread = new Thread(new ThreadStart(OutputThreadFunction));
Thread gamerThread = new Thread(new ThreadStart(GamerThreadFunction));
inputThread.Start();
outputThread.Start();
gamerThread.Start();
while(!gamer_.ExitState)
Thread.Sleep(100);
exit_ = true;
Thread.Sleep(100);//give some time
inputThread.Abort();
outputThread.Abort();
gamerThread.Abort();
}
private void InputThreadFunction()
{
while (!exit_)
{
connector_.Input(Console.ReadLine());//The problem is here
waitForInput.Set();
waitForOutput.Set();
}
}
private void OutputThreadFunction()
{
while (!exit_)
{
waitForOutput.WaitOne();
Console.Write(connector_.Output()); // end line will return connector_.Output
}
}
private void GamerThreadFunction()
{
while (!exit_)
{
switch (gamer_.DoJob())
{
case 0:
exit_ = true;
break;
case 1:
waitForOutput.Set();
break;
case 2:
waitForInput.WaitOne();
break;
}
}
}
}
}
Կարամ այսքան մասը տալ:
Էջանիշներ