所以我正在使用Kinect SDK制作一个应用程序,而且进展顺利!我正在尝试制作一个按钮拍照,但我希望延迟拍摄照片的代码让人们有时间摆出姿势。我尝试过使用System.Threading.Thread.Sleep(3000);但是会发生的事情是整个事情都冻结了(是的,我知道这就是睡眠所做的......)并且无论如何都会使用第一帧。所以现在我正在尝试使用定时器和定时事件,但由于无法使其静态而不断出现错误(Kinect事情)。
public class Timer1
{
private System.Timers.Timer aTimer;
public void Main()
{
aTimer = new System.Timers.Timer(3000);
//This is where the problem is. I'm getting "Cannot access a non-static member of outer type 'KinectButton.MainWindow' via nested type 'KinectButton.MainWindow.Timer1'
aTimer.Elapsed += new ElapsedEventHandler(takepicture);
aTimer.Interval = 1000;
aTimer.Enabled = True;
}
}
[private void takepicture(object sender, ElapsedEventArgs e)
{
BitmapSource image = (BitmapSource)videoStream.Source;
image.Save(DateTime.Now.ToString("ddMMyyyy HHmmss") + ".jpg", ImageFormat.Jpeg);
}
private void button7_Click(object sender, RoutedEventArgs e)
{
//Here I'm also getting "'KinectButton.MainWindow.Timer1' does not contain a definition for 'Enabled'"
Timer1.Enabled = true;
}
private void Timer1_Tick(object sender, EventArgs e)
{
//Here I'm getting "'KinectButton.MainWindow.Timer1' does not contain a definition for 'Enabled'" again...
Timer1.Enabled = false;
}
好吧,如果你们能提供帮助,请告诉我们!
答案 0 :(得分:1)
我认为这是一个WPF应用程序?我想你会想要使用Windows.Threading.DispatcherTimer
Private timer As New Windows.Threading.DispatcherTimer
timer.Interval = New TimeSpan(0, 0, 0, 1)
AddHandler timer.Tick, AddressOf timer_Tick
timer.Start()
Private Sub timer_Tick(ByVal Sender As Object, ByVal e As EventArgs)
'do something
End Sub
是的,我知道它的vb但它应该很容易转换