Async programming using C++ /CX

The following code example illustrates async programming using the Parallel Patterns Library and C++ /CX

This code sample uses the File Picker to display a list of docx and pdf files from the user’s Document Library. It then fetches the selected file name and sets it to the Text property of the Text control.

The Xaml markup that drives the scenario above is

<Grid Background=”{StaticResource ApplicationPageBackgroundBrush}”>
<TextBox x:Name=”label” HorizontalAlignment=”Left” Height=”54″ Margin=”449,155,0,0″ TextWrapping=”Wrap” Text=”TextBox” VerticalAlignment=”Top” Width=”397″/>
<Button Content=”PPL Task Test” Click=”Button_Click_2″  HorizontalAlignment=”Left” Height=”49″ Margin=”156,209,0,0″ VerticalAlignment=”Top” Width=”153″/>
</Grid>

auto picker = ref new Windows::Storage::Pickers::FileOpenPicker();
picker->SuggestedStartLocation = Windows::Storage::Pickers::PickerLocationId::DocumentsLibrary;
picker->FileTypeFilter->Append(“.docx”);
picker->FileTypeFilter->Append(“.pdf”);

task<StorageFile^>(picker->PickSingleFileAsync()).then([this](StorageFile^ file)
{
if (file)
{
this->label->Text = file->DisplayName;
}
});


Leave a Reply

Your email address will not be published. Required fields are marked *