locked
LaunchFileAsync works at times and does not work most of the time.

    Question

  • I am trying LAunchFileAsync. This works at times and not most of the time. Here is the code that I am trying with. 

    auto folder = Windows::Storage::ApplicationData::Current->LocalFolder;
    auto fileOperation = folder->GetFileAsync(ref new String(L"test.txt"));
    fileOperation->Completed= ref new AsyncOperationCompletedHandler<StorageFile^>([](IAsyncOperation<StorageFile^>^ aFileOperation, AsyncStatus status )
    {
    switch( status )
    {
    case Windows::Foundation::AsyncStatus::Completed:

    StorageFile^ storageFile = aFileOperation->GetResults(); 
    Windows::System::LauncherOptions^ option= ref new Windows::System::LauncherOptions();
    option->DisplayApplicationPicker= true;
    option->TreatAsUntrusted = false;
    Windows::Foundation::IAsyncOperation<bool>^ operation= Windows::System::Launcher::LaunchFileAsync( storageFile,option);
    operation->Completed = ref new Windows::Foundation::AsyncOperationCompletedHandler<bool>( [](IAsyncOperation<bool>^ operation, Windows::Foundation::AsyncStatus status )
    {
    switch( status )
    {
    case AsyncStatus::Completed:
    {
    bool bResult= operation->GetResults();
    if (!bResult )
    OutputDebugStringA("Failed ...it fails here..and file does not launch");
    break;
    }
    case AsyncStatus::Error:
    break;
    }
    });
    }
    break;
    case Windows::Foundation::AsyncStatus::Error:
    break;
    }
    });


    Thursday, July 12, 2012 12:52 AM

All replies

  • Can you describe the behavior or errors you see when it doesn't work? The most common reason for a failure using these APIs is due to the file not existing in the specified path. The Association launching sample (LaunchFileInput.xaml.cpp) can easily be modified to test the exact behavior you are after.


    David Lamb



    Thursday, July 12, 2012 10:22 PM
    Moderator
  • The file is present in the path. In the above code that I've mentioned I am hitting:

    if (!bResult )
    OutputDebugStringA("Failed ...it fails here..and file does not launch");

    Association launching sample also does not work properly, it works at times and does not work most of the time.

    Saturday, July 14, 2012 1:21 AM
  • I cannot produce any inconsistent results with the Association Launching sample. It sounds as though there is something on your system interfering. Could you capture a procmon log and email it to me for review? It would also be useful if you could isolate when the problems start when installing a fresh installation.

    Was this an upgrade installation?

    DavidLam at Microsoft dot COM

    Thanks!


    David Lamb


    Monday, July 16, 2012 4:14 PM
    Moderator
  • I am having similar issues. The launch works when called from a button click, but not in response to an event like PageLoaded, or OnNavigatedTo.
    Thursday, August 09, 2012 5:32 PM