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


C# CanvasDevice.Lock方法代码示例

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


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

示例1: Go

            internal async Task Go(CancellationToken cancellationToken, CanvasDevice device, ScenarioData scenarioData)
            {
                var runner = MakeScenarioRunner();
                scenarioData.AddDataToScenarioRunner(runner);

                // Create the image source and the render target.  These sizes are hardcoded and independent of the 
                // display's DPI since we just want a small image to convince ourselves that the scenarios really are 
                // rendering the right thing.
                Image = new CanvasImageSource(device, 128, 128, 96);

                using (var rt = new CanvasRenderTarget(device, 128, 128, 96))
                {
                    // We actually run the scenario on the thread pool - XAML really falls down if you overload the UI thread.
                    var time = await Task.Run(() =>
                    {
                        // Run the scenario multiple times to try and avoid too much noise
                        List<CpuGpuTime> times = new List<CpuGpuTime>();

                        for (int i = 0; i < 10; ++i)
                        {
                            // Hold the device lock while we run the scenario - this prevents other threads
                            // from interacting with the device and interfering with our recorded time.
                            using (var deviceLock = device.Lock())
                            {
                                times.Add(RunScenario(runner, rt));
                            }
                            if (cancellationToken.IsCancellationRequested)
                                return new CpuGpuTime();
                        }

                        var cpuTimes = from entry in times select entry.CpuTimeInMs;
                        var gpuTimes = from entry in times select entry.GpuTimeInMs;

                        return new CpuGpuTime
                        {
                            CpuTimeInMs = GetAverage(cpuTimes),
                            GpuTimeInMs = GetAverage(gpuTimes)
                        };
                    }, cancellationToken);

                    Data[scenarioData.Value] = time;

                    if (cancellationToken.IsCancellationRequested)
                        return;

                    using (var ds = Image.CreateDrawingSession(Colors.Transparent))
                    {
                        ds.DrawImage(rt);

                        var timing = string.Format("{0:0.00}ms\n{1:0.00}ms", time.CpuTimeInMs, time.GpuTimeInMs);
                        ds.DrawText(timing, 0, 0, Colors.White);
                        ds.DrawText(timing, 1, 1, Colors.Black);
                    }
                }

                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("Image"));
                    PropertyChanged(this, new PropertyChangedEventArgs("Summary"));
                }
            }
开发者ID:fengweijp,项目名称:Win2D,代码行数:61,代码来源:SpriteBatchPerf.xaml.cs


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