0

所以我正在使用 Kinect SDK 制作一个应用程序,并且进展顺利!我正在尝试让按钮拍照,但我希望延迟拍照的代码,以便人们有时间摆姿势。我试过使用 System.Threading.Thread.Sleep(3000); 但发生的事情是整个事情都冻结了(是的,我知道这就是 sleep 所做的......)并且它仍然使用第一帧。所以现在我正在尝试使用 Timer 和 Timed Event,但由于无法使其成为静态(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;
}

好吧,让我知道你们是否可以提供帮助!

4

1 回答 1

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,但它应该很容易转换

于 2013-08-07T16:04:49.710 回答