本文整理汇总了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();
}
示例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();
}
示例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));
}
}
示例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();
}