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


C# Task.First方法代码示例

本文整理汇总了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;
        }
开发者ID:scnerd,项目名称:Picasso,代码行数:86,代码来源:Child.cs


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