当前位置: 首页>>代码示例>>C#>>正文


C# BackgroundWorker.BeginWorkerAsync方法代码示例

本文整理汇总了C#中System.ComponentModel.BackgroundWorker.BeginWorkerAsync方法的典型用法代码示例。如果您正苦于以下问题:C# BackgroundWorker.BeginWorkerAsync方法的具体用法?C# BackgroundWorker.BeginWorkerAsync怎么用?C# BackgroundWorker.BeginWorkerAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ComponentModel.BackgroundWorker的用法示例。


在下文中一共展示了BackgroundWorker.BeginWorkerAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WaitAsync

 public static async Task WaitAsync(int miliseconds)
 {
     var worker = new BackgroundWorker();
     worker.DoWork += (a, b) =>
     {
         Thread.Sleep(miliseconds);
     }; ;
     await worker.BeginWorkerAsync();
 }
开发者ID:radu-ungureanu,项目名称:Grimacizer,代码行数:9,代码来源:Extensions.cs

示例2: OnNavigatedTo

        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.NavigationMode == NavigationMode.Back)
                return;

            SystemTray.IsVisible = true;

            int width, height;
            using (var db = new GrimacizerContext(GrimacizerContext.ConnectionString))
            {
                var settings = db.Settings.FirstOrDefault();
                width = settings.DefaultImagePixelWidth;
                height = settings.DefaultImagePixelHeight;
            }
            ImageSource = LocalImagesHelper.ReadImageFromIsolatedStorage(Constants.DEFAULT_FACE_PHOTO, width, height);

            var worker = new BackgroundWorker();
            worker.DoWork += (sender, arg) =>
            {
                FaceSdkHelper.Initialize();
            };
            await worker.BeginWorkerAsync();

            var sdkImg = ImageConverter.SystemToSdk(ImageSource);
            var result = FaceSdkHelper.Detect(sdkImg);
            ImageSource = ImageConverter.SdkToSystem(result);

            if (SdkHelper.foundFace == true && SdkHelper.results.Count == 1)
            {
                (ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true;
                (ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = true;
                IsCalculating = false;
            }
            else
            {
                MessageBox.Show("Camera did not detect your face! Try again!");
                NavigationService.GoBack();
            }

            FaceSdkHelper = null;
            GC.Collect();
        }
开发者ID:radu-ungureanu,项目名称:Grimacizer,代码行数:42,代码来源:ProfileCreated.xaml.cs

示例3: timer_Tick

        async void timer_Tick(object sender, EventArgs e)
        {
            try
            {
                var availableSeconds = (DateTime.Now - this.startDate).Seconds;
                Timer = availableSeconds.ToString();

                if (availableSeconds % 5 == 0)
                {
                    Dispatcher.BeginInvoke(async delegate()
                    {
                        if (cam != null)
                        {
                            await cam.CaptureImageAsync();
                        }
                    });

                    var rnd = new Random();
                    int randomLevel = rnd.Next(0, Constants.AvailableLevels + 1);

                    while (selectedPhotos.Contains(randomLevel))
                    {
                        randomLevel = rnd.Next(1, Constants.AvailableLevels + 1);
                    }
                    selectedPhotos.Add(randomLevel);

                    string pic = "/Images/Levels/L" + randomLevel + ".JPG";
                    bmi = new BitmapImage(new Uri(pic, UriKind.Relative));
                    grimacePattern.Source = bmi;
                }

                if (availableSeconds > 19)
                {
                    timer.Stop();

                    IsCalculating = true;
                    Timer = string.Empty;
                    Message = string.Empty;

                    var worker = new BackgroundWorker();
                    DoWorkEventHandler workerHandler = null;

                    this.FaceSdkHelper.Initialize();

                    for (int i = 1; i < 5; i++)
                    {
                        workerHandler = (a, b) =>
                        {
                            startHardWork(i);
                        };
                        worker.DoWork -= workerHandler;
                        worker.DoWork += workerHandler;
                        await worker.BeginWorkerAsync();
                    }

                    IsCalculating = false;

                    NavigationService.Navigate(new Uri(Pages.MainPage, UriKind.RelativeOrAbsolute));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Something bad appeared! Going back..");
                NavigationService.Navigate(new Uri(Pages.MainPage, UriKind.RelativeOrAbsolute));
            }
        }
开发者ID:radu-ungureanu,项目名称:Grimacizer,代码行数:66,代码来源:Survival.xaml.cs

示例4: startHardWork

        private async Task startHardWork()
        {
            worker = new BackgroundWorker();
            worker.DoWork += (sender, arg) =>
            {
                FaceSdkHelper.Initialize();
            };
            await worker.BeginWorkerAsync();

            var sdkImg = ImageConverter.SystemToSdk(imageBitmap);
            var result = FaceSdkHelper.Detect(sdkImg);

            if (SdkHelper.foundFace == true && SdkHelper.results.Count == 1)
            {
                var shape = SdkHelper.results.FirstOrDefault();

                var defaultFaceCalculations = Calculus.ReadDefaultFaceCalculations();
                var array = FaceCalculationsHelpers.FromFaceCalculationsToVector(defaultFaceCalculations);

                var calculatedFaceCalculations = Calculus.GetFaceCalculationsFromShape(shape);
                var resultArray = FaceCalculationsHelpers.FromFaceCalculationsToVector(calculatedFaceCalculations);

                var conditions = new Conditions();
                var resultFromCalculus = conditions.GetLevelVerifierFunction(Level).Invoke(array, resultArray);

                if (resultFromCalculus != 0)
                {
                    using (var db = new GrimacizerContext(GrimacizerContext.ConnectionString))
                    {
                        var passedLevels = db.Settings.FirstOrDefault()._16_PassedLevels;
                        db.Settings.FirstOrDefault()._16_PassedLevels = Math.Max(passedLevels, Level);

                        var level = db.Levels.FirstOrDefault(t => t.Level == Level);
                        level.Stars = Math.Max(resultFromCalculus, level.Stars);

                        db.SubmitChanges();
                    }
                    MessageBox.Show("Level passed. You won " + resultFromCalculus + " point" + (resultFromCalculus > 1 ? "s!" : "!"));
                }
                else
                {
                    InGameLifeHelpers.LoseLife();
                    MessageBox.Show("Level failed");
                }
            }
            else
            {
                MessageBox.Show("Camera did not detect your face! Try again!");
            }

            NavigationService.Navigate(new Uri(Pages.GeneralGameplay_Adventure, UriKind.RelativeOrAbsolute));
            FaceSdkHelper = null;
            GC.Collect();
        }
开发者ID:radu-ungureanu,项目名称:Grimacizer,代码行数:54,代码来源:TakePhoto.xaml.cs


注:本文中的System.ComponentModel.BackgroundWorker.BeginWorkerAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。