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


C# CoreDispatcher.RunAsync方法代码示例

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


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

示例1: ExecuteAsync

        public static async void ExecuteAsync(CoreDispatcher dispatcher)
        {
            var task = dispatcher.RunAsync(CoreDispatcherPriority.High, ()
                 => CmdGo.Instance.Execute(null));

            //TaskScheduler.Current
            await task;
        }
开发者ID:akrisiun,项目名称:iot-lib,代码行数:8,代码来源:Commands.cs

示例2: InvokeOnUI

        public async static Task InvokeOnUI(CoreDispatcher d, Action a)
#endif
        {
#if WINDOWS_PHONE 
            d.BeginInvoke(a);
            await Task.Delay(0);
#elif !NETFX_CORE
            await d.BeginInvoke(a);
#else
            await d.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(a));
#endif
        }
开发者ID:jcookems,项目名称:freezing-ninja,代码行数:12,代码来源:UI.cs

示例3: BeginInvoke

        /// <summary>
        /// Forwards the BeginInvoke to the current application's <see cref="Dispatcher"/>.
        /// </summary>
        /// <param name="method">Method to be invoked.</param>
        /// <param name="arg">Arguments to pass to the invoked method.</param>
        public Task BeginInvoke(Delegate method, params object[] arg)
        {
            if (dispatcher != null)
                return dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => method.DynamicInvoke(arg)).AsTask();

            var coreWindow = CoreApplication.MainView.CoreWindow;
            if (coreWindow != null)
            {
                dispatcher = coreWindow.Dispatcher;
                return dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => method.DynamicInvoke(arg)).AsTask();
            }
            else
                return Task.Delay(0);
        }
开发者ID:xperiandri,项目名称:PortablePrism,代码行数:19,代码来源:DefaultDispatcher.Desktop.cs

示例4: InitializeAsync

 public async Task<ImagePackage> InitializeAsync(CoreDispatcher dispatcher, Image image, Uri uriSource,
     IRandomAccessStream streamSource, CancellationTokenSource cancellationTokenSource)
 {
     _bitmapImage = new BitmapImage();
     await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         var uri = image.Tag as Uri;
         if (uri == uriSource)
         {
             image.Source = _bitmapImage;
         }
     });
     await _bitmapImage.SetSourceAsync(streamSource).AsTask(cancellationTokenSource.Token);
     return new ImagePackage(this, _bitmapImage, _bitmapImage.PixelWidth, _bitmapImage.PixelHeight);
 }
开发者ID:chenrensong,项目名称:ImageLib.UWP,代码行数:15,代码来源:DefaultDecoder.cs

示例5: SearchForUsbDevices

 public static void SearchForUsbDevices(CoreDispatcher dispatcher)
 {
     DeviceWatcher deviceWatcher =
         DeviceInformation.CreateWatcher(HidDevice.GetDeviceSelector(uPage, uid));
     deviceWatcher.Added += (s, a) => dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
     {
         HidDevice hidDevice = await HidDevice.FromIdAsync(a.Id, FileAccessMode.ReadWrite);
         var launcher = new ProgrammatorDevice(hidDevice);
         if (UsbDeviceFound != null)
         {
             UsbDeviceFound(null, new ProgrammatorDeviceEventArgs(launcher));
         }
           
         deviceWatcher.Stop();
     });
     deviceWatcher.Start();
 }
开发者ID:MaciejBaj,项目名称:device-communicator,代码行数:17,代码来源:ProgrammatorDevice.cs

示例6: DisplayDialog

        /// <summary>
        /// Display a dialog box with a custom action when the user presses "OK"
        /// </summary>
        /// <param name="dispatcher">UI thread's dispatcher</param>
        /// <param name="content">Message box content</param>
        /// <param name="title">Message box title</param>
        /// <param name="okHandler">Callback executed when the user presses "OK"</param>
        public static void DisplayDialog(CoreDispatcher dispatcher, string content, string title, UICommandInvokedHandler okHandler)
        {
            Debug.WriteLine("Dialog requested: " + title + " - " + content);

            var unused = dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
            {
                var dialog = new MessageDialog(content, title);

                if (okHandler != null)
                {
                    dialog.Commands.Add(new UICommand("OK", okHandler));
                }
                else
                {
                    dialog.Commands.Add(new UICommand("OK"));
                }

                dialog.DefaultCommandIndex = 0;
                dialog.CancelCommandIndex = 0;

                await dialog.ShowAsync();
            });
        }
开发者ID:cmathser,项目名称:moonlight-windows,代码行数:30,代码来源:DialogUtils.cs

示例7: InitializeAsync

 public async Task<ImagePackage> InitializeAsync(CoreDispatcher dispatcher, Image image, Uri uriSource,
     IRandomAccessStream streamSource,
      CancellationTokenSource cancellationTokenSource)
 {
     byte[] bytes = new byte[streamSource.Size];
     await streamSource.ReadAsync(bytes.AsBuffer(), (uint)streamSource.Size, InputStreamOptions.None).AsTask(cancellationTokenSource.Token);
     int width, height;
     WriteableBitmap writeableBitmap = null;
     if (WebpCodec.GetInfo(bytes, out width, out height))
     {
         writeableBitmap = new WriteableBitmap(width, height);
         await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
          {
              var uri = image.Tag as Uri;
              if (uri == uriSource)
              {
                  image.Source = writeableBitmap;
              }
          });
         WebpCodec.Decode(writeableBitmap, bytes);
     }
     return new ImagePackage(this, writeableBitmap, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight);
 }
开发者ID:chenrensong,项目名称:ImageLib.UWP,代码行数:23,代码来源:WebpDecoder.cs

示例8: runInForeground

 public static void runInForeground(CoreDispatcher Dispatcher, Action actionToRun)
 {
     if (Dispatcher != null)
         Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => actionToRun());
     else
         Windows.System.Threading.ThreadPool.RunAsync(handler => actionToRun());
 }
开发者ID:adjust,项目名称:windows_sdk,代码行数:7,代码来源:UtilUap.cs

示例9: InvokeSync

        private static void InvokeSync(CoreDispatcher dispatcher, Action action)
        {
            Exception exception = null;

            // TODO Research dispatcher.RunIdleAsync
            dispatcher.RunAsync(
                CoreDispatcherPriority.Normal, 
                () =>
                    {
                        try
                        {
                            action();
                        }
                        catch (Exception ex)
                        {
                            exception = ex;
                        }
                    }).AsTask().Wait();

            if (exception != null)
            {
                throw exception;
            }
        }
开发者ID:goldbillka,项目名称:Winium.StoreApps,代码行数:24,代码来源:CommandBase.cs

示例10: ConnectToWifi

        private async void ConnectToWifi(WiFiAvailableNetwork network, PasswordCredential credential, CoreDispatcher dispatcher)
        {
            var didConnect = credential == null ?
                networkPresenter.ConnectToNetwork(network, Automatic) :
                networkPresenter.ConnectToNetworkWithPassword(network, Automatic, credential);

            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                SwitchToItemState(network, WifiConnectingState, false);
            });

            if (await didConnect)
            {
                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    NavigationUtils.NavigateToScreen(typeof(MainPage));
                });
            }
            else
            {
                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    var item = SwitchToItemState(network, WifiInitialState, false);
                    item.IsSelected = false;
                });
            }
        }
开发者ID:MicrosoftEdge,项目名称:WebOnPi,代码行数:27,代码来源:OOBENetwork.xaml.cs

示例11: InitializeAsync

        public async Task<ImageSource> InitializeAsync(CoreDispatcher dispatcher,
            IRandomAccessStream streamSource, CancellationTokenSource cancellationTokenSource)
        {

            var inMemoryStream = new InMemoryRandomAccessStream();
            var copyAction = RandomAccessStream.CopyAndCloseAsync(
                           streamSource.GetInputStreamAt(0L),
                           inMemoryStream.GetOutputStreamAt(0L));
            await copyAction.AsTask(cancellationTokenSource.Token);

            var bitmapDecoder = await BitmapDecoder.
                CreateAsync(BitmapDecoder.GifDecoderId, inMemoryStream).AsTask(cancellationTokenSource.Token).ConfigureAwait(false);
            var imageProperties = await RetrieveImagePropertiesAsync(bitmapDecoder);
            var frameProperties = new List<FrameProperties>();
            for (var i = 0u; i < bitmapDecoder.FrameCount; i++)
            {
                var bitmapFrame = await bitmapDecoder.GetFrameAsync(i).AsTask(cancellationTokenSource.Token).ConfigureAwait(false); ;
                frameProperties.Add(await RetrieveFramePropertiesAsync(i, bitmapFrame));
            }

            _frameProperties = frameProperties;
            _bitmapDecoder = bitmapDecoder;
            _imageProperties = imageProperties;
            _dispatcher = dispatcher;

            await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
             {
                 CreateCanvasResources();
             });

            _isInitialized = true;
            return _canvasImageSource;
        }
开发者ID:yyx290799684,项目名称:ImageLib.UWP,代码行数:33,代码来源:GifDecoder.cs

示例12: Execute

        public async void Execute(CoreDispatcher dispatcher)
        {
            // TODO: Implement a cancellation token to allow for a task cancellation
            // when the app is closed or put in sleep mode
            var RootFilter = new HttpBaseProtocolFilter();
            RootFilter.CacheControl.ReadBehavior = Windows.Web.Http.Filters.HttpCacheReadBehavior.MostRecent;
            RootFilter.CacheControl.WriteBehavior = Windows.Web.Http.Filters.HttpCacheWriteBehavior.NoCache;

            dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                using (var httpClient = new HttpClient())
                {
                    httpClient.BaseAddress = new Uri(this.BaseUrl);
                    httpClient.DefaultRequestHeaders.Accept.Clear();
                    httpClient.DefaultRequestHeaders.Add("Cache-Control", "no-cache");
                    httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    string json_object = "webservice.php?";

                    if (this._parameters.Count > 0)
                    {
                        foreach (KeyValuePair<string, string> param in this._parameters)
                        {

                            json_object += string.Format("{0}={1}&", param.Key, param.Value);
                        }
                    }

                    HttpResponseMessage response = httpClient.GetAsync(json_object).Result;
                    string statusCode = response.StatusCode.ToString();
                    response.EnsureSuccessStatusCode();

                    Task<string> responseBody = response.Content.ReadAsStringAsync();

                    this.BaseUrl = "http://66.90.73.236/bgconvention/webservice.php";

                    _callback(new ApiResponse(responseBody.Result));

                }

            });

        }
开发者ID:amasolini,项目名称:brid-wp,代码行数:43,代码来源:ApiManager.cs

示例13: ExecuteOnUIThread

 public static void ExecuteOnUIThread(Action action, CoreDispatcher dispatcher)
 {
     if (dispatcher.HasThreadAccess)
         action();
     else
     {
         var asyncaction = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => action());
     }
 }
开发者ID:kubaszostak,项目名称:arcgis-toolkit-dotnet,代码行数:9,代码来源:CompatUtility.cs

示例14: Run

        internal void Run(IAsyncAction action, CoreDispatcher uiDispatcher)
        {
            bool cont = true;
            AppTaskResult? lastResult = null;
            while (cont)
            {
                var task = TaskStack.Pop();
                object data;
                bool success = task(Parameter, action, lastResult, out data);
                lastResult = new AppTaskResult(success, data, lastResult);
                cont = (SuccessFallbackLimit == -1 || SuccessFallbackLimit > CurrentLevel) && TaskStack.Count > 0;
                CurrentLevel++;
            }
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            if (action.Status != AsyncStatus.Canceled)
                uiDispatcher.RunAsync(CoreDispatcherPriority.High, () => { CompletedCallback(lastResult.Value); });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }
开发者ID:AlexKven,项目名称:OneAppAway-RTM,代码行数:18,代码来源:TaskManager.cs

示例15: InitializeAsync

        public async Task<ImagePackage> InitializeAsync(CoreDispatcher dispatcher, Image image, Uri uriSource,
            IRandomAccessStream streamSource, CancellationTokenSource cancellationTokenSource)
        {
   
            var bitmapDecoder = ImagingCache.Get<BitmapDecoder>(uriSource);
            if (bitmapDecoder == null)
            {
                var inMemoryStream = new InMemoryRandomAccessStream();
                var copyAction = RandomAccessStream.CopyAndCloseAsync(
                               streamSource.GetInputStreamAt(0L),
                               inMemoryStream.GetOutputStreamAt(0L));
                await copyAction.AsTask(cancellationTokenSource.Token);
                bitmapDecoder = await BitmapDecoder.CreateAsync(BitmapDecoder.GifDecoderId, inMemoryStream);
                ImagingCache.Add(uriSource, bitmapDecoder);
            }

            var imageProperties = await RetrieveImagePropertiesAsync(bitmapDecoder);
            var frameProperties = new List<FrameProperties>();

            for (var i = 0u; i < bitmapDecoder.FrameCount; i++)
            {
                var bitmapFrame = await bitmapDecoder.GetFrameAsync(i).AsTask(cancellationTokenSource.Token).ConfigureAwait(false); ;
                frameProperties.Add(await RetrieveFramePropertiesAsync(i, bitmapFrame));
            }

            _frameProperties = frameProperties;
            _bitmapDecoder = bitmapDecoder;
            _imageProperties = imageProperties;
            _dispatcher = dispatcher;

            await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
             {
                 CreateCanvasResources();
                 var uri = image.Tag as Uri;
                 if (uri == uriSource)
                 {
                     image.Source = _canvasImageSource;
                 }
             });

            _isInitialized = true;
            return new ImagePackage(this, _canvasImageSource, _imageProperties.PixelWidth, _imageProperties.PixelHeight); ;
        }
开发者ID:chenrensong,项目名称:ImageLib.UWP,代码行数:43,代码来源:GifDecoder.cs


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