本文整理汇总了C#中System.Threading.Tasks.Task.First方法的典型用法代码示例。如果您正苦于以下问题:C# Task.First方法的具体用法?C# Task.First怎么用?C# Task.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Tasks.Task
的用法示例。
在下文中一共展示了Task.First方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ScanImageSection
/// <summary>
///
/// </summary>
/// <param name="ImgSec"></param>
/// <param name="ColorForgive"></param>
/// <param name="ColorDetail"></param>
/// <param name="MinMargin"></param>
/// <returns></returns>
internal static Child[] ScanImageSection(ImageSection ImgSec, int ColorForgive, int ColorDetail, int MinMargin, Child Parent = null)
{
#if GUIOUTPUT
mScannedPx = 0;
int MaxSize = ImgSec.Width * ImgSec.Height;
frmImgSecDisplay DisplayOut = null;
//DisplayOut.Show();
//Master.sInvokable.Invoke(Master.sAddable, null => {return new frmImgSecDisplay();}, DisplayOut);
MakeForm NewDisp = delegate() { return new frmImgSecDisplay(); };
AssignForm AssDisp = delegate(System.Windows.Forms.Form ToAssign) { DisplayOut = (frmImgSecDisplay)ToAssign; };
Master.sInvokable.Invoke(Master.sAddable, new object[] { NewDisp, AssDisp });
#endif
//Break the image into ImageSections
List<ImageSection> Sections = new List<ImageSection>();
ImageSectionFactory Factory;
for (int y = 0; y < ImgSec.Height; y++)
{
for (int x = 0; x < ImgSec.Width; x++)
{
if (ImgSec.GetPixel(x, y).A == byte.MaxValue)
{
Factory = new ImageSectionFactory(new Point(x, y), ColorForgive, ColorDetail
#if GUIOUTPUT
,DisplayOut
#endif
);
Sections.Add(Factory.Recognize(ref ImgSec, x, y));
#if GUIOUTPUT
UpdateDisplay((mScannedPx += Factory.SelectedPixels().Count()), MaxSize, 0);
#endif
}
}
}
Sections.RemoveAll(imsec => imsec == null);
//Figure out if it just selected the whole thing. If so, cancel the scan
if (Sections.Count == 1 && Sections[0].Size == ImgSec.Size)
return new Child[0];
//Figure out which ones of those are too small and should be discounted
for (int remove = 0; remove < Sections.Count; remove++)
{
if (Sections[remove].PixelsUsed().Length <= MinMargin) Sections.RemoveAt(remove);
}
Sections.TrimExcess();
// Once that's done, turn the remaining Image Sections into Children
Child[] Children = new Child[Sections.Count];
#if MULTITHREAD
Task<Child>[] Tasks = new Task<Child>[Sections.Count];
#endif
for (int i = 0; i < Sections.Count; i++)
{
#if MULTITHREAD
Tasks[i] = new Task<Child>(s => Child.FromSection((Child)((object[])s)[0], (ImageSection)((object[])s)[1]), new object[]{Parent, Sections[i]});
Tasks[i].Start();
#else
Children[i] = Child.FromSection(Parent, Sections[i]);
#endif
#if GUIOUTPUT
UpdateDisplay(MaxSize, MaxSize, 1);
#endif
}
#if MULTITHREAD
try
{
while (Tasks.Any(t => !t.IsCompleted)) Tasks.First(t => !t.IsCompleted).Wait();
}
catch (NullReferenceException) { }
for (int i = 0; i < Tasks.Length; i++)
{
Children[i] = Tasks[i].Result;
}
#endif
return Children;
}