c# - Async Task to Youtube -
i'm new actually. have short application check whether application can authentication asynchronously youtube , return application it's track. here snippet of code
private async void button1_click(object sender, routedeventargs e) { await youtubeauth(); messagebox.show(token); } private async task youtubeauth() { oauth2credential = await googlewebauthorizationbroker.authorizeasync( new clientsecrets { clientid = youtubeclientid, clientsecret = youtubeclientsecret }, // oauth 2.0 access scope allows application upload files // authenticated user's youtube channel, doesn't allow other types of access. new[] { youtubeservice.scope.youtubeupload }, "user", cancellationtoken.none ); token = oauth2credential.token.tokentype; }
the code messagebox.show(token);
never been executed.
edit:
i have tried other simpler code below , still messagebox never triggered
private async void button1_click(object sender, routedeventargs e) { await youtubeauth(); messagebox.show(token); } private async task youtubeauth() { token = "test token"; }
this seems interesting. have written fastly wpf example app verify
mainwindow.xaml
<window x:class="testasynctasktoyoutube.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:testasynctasktoyoutube" mc:ignorable="d" title="mainwindow" height="350" width="525"> <grid> <button x:name="button" content="button" /> </grid> </window>
mainwindow.xaml.cs
using system.threading.tasks; using system.windows; namespace testasynctasktoyoutube { public partial class mainwindow : window { private string token; public mainwindow() { initializecomponent(); button.click += button_click; } private async void button_click(object sender, routedeventargs e) { await youtubeauth(); messagebox.show(token); } private task<int> youtubeauth() { token = "test token"; return task.fromresult(0); } } }
no problems here. messagebutton fires should be. sure code bit different mine anywhere :|
how can you?
edit: avoiding task.fromresult() (.net 4.5 feature)
private async task youtubeauth() { token = "test token"; }
Comments
Post a Comment