我有以下结构
private struct sData{
public int volume;
public System.Timers.Timer aliveTimer;
public void OnTimedEvent(object source, ElapsedEventArgs e)
{
Console.WriteLine("this = " + volume);// I cannot access volume here
}
}
当时间过去了我想改变音量值并且我无法在 OnTimedEvent 中访问它我使用这个代码来启动结构和计时器:
sData ret = new sData();
ret.volume = rand.Next(1, 10) * 100;
ret.aliveTimer = new System.Timers.Timer(1000);
ret.aliveTimer.Elapsed += new ElapsedEventHandler(sData.OnTimedEvent);
ret.aliveTimer.Start();
我应该怎么办?