0
所以,没有张贴在这里我的整个项目,我会总结一下,尽我所能:目标在不同的类一个对象变量
class Program
{
static void Main(string[] args)
{
Thing one = new Thing();
one.addTimer(10);
one.addTimer(4);
one.addTimer(2);
one.addTimer(8);
}
}
class Counter
{
private int Seconds;
private int TimerNum;
public Counter(int SecondsX)
{
Seconds = (SecondsX * 1000);
}
public void TimerCall(){
Thread.sleep(Seconds);
CounterCallBack();
}
public void CounterCallBack()
{
Console.WriteLine("Timer " + TimerNum + " Done");
//Then the time is up the call back is executed
//The issue I am having is how do I trigger the next timer for the list timers to go from hear automatically. It would send back TimerNum to Thing.Continue
}
}
class Thing
{
List<int> timers = new List<int>();
public Thing()
{
}
public void addTimer(new Timer(int SecondsToAdd))
{
timers.Add(SecondsToAdd);
}
public void StartTimers(){
timers[0].TimerCall();
}
public void Continue(int LastRun){
if(timers.count()-1>= LastRun){
timers[LastRun].TimerCall();
}
}
}
所以我需要从柜台存取继续方法踢关闭下一个计时器。 或者我需要找到一种方法来做同样的事情。 然而,用户需要能够编辑,添加和删除定时器(从Program
类情况发生)
请记住,在我的程序(这是一个简化版本)Counter
是一个计时器调用和回调运行异步。
甚至有可能吗?或者我是否需要放弃这种方法并从第一方开始?
另外,我知道这很粗糙,但是这个项目是为了慈善事业,我计划一旦我得到这个原型工作,就清理它。另外我是16岁。所以,请给予任何帮助,将不胜感激。
你的意思是做timers.Add(新的Timer(SecondsToAdd));并使列表定时器的类型定时器,而不是int?你在一个int上调用TimerCall()而不是一个Timer。 –
是的,谢谢。我想我可以通过在继续运行的程序中添加一个方法并在Counter中创建一个对象变量来实现。然而,这只是混乱,我仍然希望有人找到一个更好的方式来做到这一点。 –