Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在csharp中进行解锁呼叫_C#_Asynchronous_Kinect_Kinect Sdk - Fatal编程技术网

C# 如何在csharp中进行解锁呼叫

C# 如何在csharp中进行解锁呼叫,c#,asynchronous,kinect,kinect-sdk,C#,Asynchronous,Kinect,Kinect Sdk,我正在开发一个Kinect应用程序,它可以进行年龄/性别分类。我已经开发了一个代码,可以拍摄颜色流的快照,在裁剪头部关节周围的图像后,可以使用face++api对图像进行性别分类 System.Timers.Timer myTimer = new System.Timers.Timer(); myTimer.Elapsed += new ElapsedEventHandler(TakeImagesTimely); myTimer.Interval

我正在开发一个Kinect应用程序,它可以进行年龄/性别分类。我已经开发了一个代码,可以拍摄颜色流的快照,在裁剪头部关节周围的图像后,可以使用face++api对图像进行性别分类

        System.Timers.Timer myTimer = new System.Timers.Timer();
        myTimer.Elapsed += new ElapsedEventHandler(TakeImagesTimely);
        myTimer.Interval = 20000; // 1000 ms is one second
        myTimer.Start();



        public void TakeImagesTimely(object source, ElapsedEventArgs e)
        {
           this.Dispatcher.Invoke((Action)(() =>
            {
            // code here will run every 20 second

            if (X == 0 || Y == 0) { Console.WriteLine("sdsds");  return; }
                screen("Kinect123", faceImg);
                String myPhotos = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                Bitmap bmp = new Bitmap(System.IO.Path.Combine(myPhotos, "Kinect123" + ".png"));
                Bitmap bmpCrop = CropBitmap(bmp, X - 100, Y - 30, 200, 100);
                BitmapSource bmpCropSrc = ConvertBitmap(bmpCrop);
                if (bmpCrop == null || bmpCropSrc == null) { return; }
                screen1("Kinect789", bmpCropSrc);
            }));
        }
这里screen函数获取颜色流的快照,然后在头部坐标周围裁剪图像后,screen1函数将裁剪后的图像上传到云上,并调用face++api进行年龄/性别分类

我的问题是screen1函数需要3-4秒来进行分类,这会挂起kinect的连续流。我知道我必须对screen1函数使用异步/取消阻止调用,但我不知道如何进行


请引导我完成此任务。

尝试在任务中包装screen1调用

例如:

Task screen1Task = Task.Run( () => {
    screen1("Kinect789", bmpCropSrc);
});
这将要求您在父方法上声明async关键字。如果您不想让screen1Task着火并被遗忘,您还需要在某个时候等待screen1Task


更多示例:

我一生中从未编写过任何C代码,但是,一定有一个Thread类?@JUnitUserRendel实际上我已经尝试过创建Thread对象,但无法使它完成我的工作。尽管我仍在编写它。Thnx:screen1函数将在每4秒后调用一次,在这段时间内,对screen1的前一次调用可能尚未完成。您的上述解决方案能否处理这种情况?是的。在再次调用之前,您需要等待任务。我使用了…但在我的代码中,api的返回类型是Cloudinary对象…然后我如何使用task来存储它。如果需要返回对象,请使用task,其中T是您的对象类型。所以,当您等待任务时,它将返回一个Cloudinary。你发布的文章应该很好地涵盖了这一点。