本文整理汇总了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;
}
示例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
}
示例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);
}
示例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);
}
示例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();
}
示例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();
});
}
示例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);
}
示例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());
}
示例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;
}
}
示例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;
});
}
}
示例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;
}
示例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));
}
});
}
示例13: ExecuteOnUIThread
public static void ExecuteOnUIThread(Action action, CoreDispatcher dispatcher)
{
if (dispatcher.HasThreadAccess)
action();
else
{
var asyncaction = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => action());
}
}
示例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
}
示例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); ;
}