Launcher.LaunchFileAsync 메서드

정의

오버로드

LaunchFileAsync(IStorageFile)

지정된 파일과 연결된 기본 앱을 시작합니다.

LaunchFileAsync(IStorageFile, LauncherOptions)

지정된 옵션을 사용하여 지정된 파일과 연결된 기본 앱을 시작합니다.

LaunchFileAsync(IStorageFile)

지정된 파일과 연결된 기본 앱을 시작합니다.

public:
 static IAsyncOperation<bool> ^ LaunchFileAsync(IStorageFile ^ file);
/// [Windows.Foundation.Metadata.Overload("LaunchFileAsync")]
 static IAsyncOperation<bool> LaunchFileAsync(IStorageFile const& file);
[Windows.Foundation.Metadata.Overload("LaunchFileAsync")]
public static IAsyncOperation<bool> LaunchFileAsync(IStorageFile file);
function launchFileAsync(file)
Public Shared Function LaunchFileAsync (file As IStorageFile) As IAsyncOperation(Of Boolean)

매개 변수

file
IStorageFile

파일입니다.

반환

시작 작업입니다.

특성

예제

이 예제에서는 LaunchFileAsync(IStorageFile)를 사용하여 앱 패키지에 포함된 파일을 시작합니다.

async void DefaultLaunch()
{
   // Path to the file in the app package to launch
   string imageFile = @"images\test.png";

   var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);

   if (file != null)
   {
      // Launch the retrieved file
      var success = await Windows.System.Launcher.LaunchFileAsync(file);

      if (success)
      {
         // File launched
      }
      else
      {
         // File launch failed
      }
   }
   else
   {
      // Could not find file
   }
}
Windows::Foundation::IAsyncAction MainPage::DefaultLaunch()
{
    // Get the app's installation folder.
    Windows::Storage::StorageFolder installFolder{ Windows::ApplicationModel::Package::Current().InstalledLocation() };

    Windows::Storage::StorageFile file{ co_await installFolder.GetFileAsync(L"Assets\\LockScreenLogo.scale-200.png") };

    if (file)
    {
        // Launch the retrieved file.
        bool success{ co_await Windows::System::Launcher::LaunchFileAsync(file) };
        if (success)
        {
            // File launched.
        }
        else
        {
            // File launch failed.
        }
    }
    else
    {
        // Couldn't find file.
    }
}
void MainPage::DefaultLaunch()
{
   auto installFolder = Windows::ApplicationModel::Package::Current->InstalledLocation;

   concurrency::task<Windows::Storage::StorageFile^> getFileOperation(installFolder->GetFileAsync("images\\test.png"));
   getFileOperation.then([](Windows::Storage::StorageFile^ file)
   {
      if (file != nullptr)
      {
         // Launch the retrieved file
         concurrency::task<bool> launchFileOperation(Windows::System::Launcher::LaunchFileAsync(file));
         launchFileOperation.then([](bool success)
         {
            if (success)
            {
               // File launched
            }
            else
            {
               // File launch failed
            }
         });
      }
      else
      {
         // Could not find file
      }
   });
}
async Sub DefaultLaunch()

   ' Path to the file in the app package to launch
   Dim imageFile = "images\test.png"

   Dim file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile)

   If file IsNot Nothing Then
      ' Launch the retrieved file
      Dim success = await Windows.System.Launcher.LaunchFileAsync(file)

      If success Then
         ' File launched
      Else
         ' File launch failed
      End If
   Else
      ' Could not find file
   End If
End Sub

설명

호출 앱은 API가 호출될 때 사용자에게 표시되어야 합니다.

이 API는 ASTA 스레드(UI 스레드라고도 함)에서 호출해야 합니다.

또한 이 API는 시작할 수 있는 파일 형식에 몇 가지 제한을 적용합니다. 실행 코드(예: .exe, .msi 및 .js 파일)가 포함된 많은 파일 형식은 시작이 차단됩니다. 이 제한은 시스템을 수정할 수 있는 잠재적으로 악의적인 파일로부터 사용자를 보호합니다.

위의 이유로 인해 시작이 실패하면 API가 성공하고 비동기 작업에서 FALSE를 반환합니다. 위의 제한이 현재 시작에 적용되는지 여부를 쿼리할 수 없으므로 호출 앱은 시작이 성공했다고 가정해서는 안 되며 실패한 경우 대체 메커니즘을 제공해야 합니다. 가능한 해결 방법은 사용자에게 파일을 저장하도록 요청하고 사용자에게 바탕 화면에서 파일을 열도록 지시하는 것입니다.

사용자가 기본 앱을 시작하는 대신 앱을 선택할 수 있도록 하려면 LauncherOptions.DisplayApplicationPicker 속성을 설정합니다.

파일이 안전하지 않을 수 있다는 경고를 표시하려면 LauncherOptions.TreatAsUntrusted 속성을 설정합니다.

파일이 연결된 앱에 전달됩니다. 연결된 앱이 데스크톱 앱인 경우 셸 실행 메커니즘을 사용하여 파일이 전달됩니다.

추가 정보

적용 대상

LaunchFileAsync(IStorageFile, LauncherOptions)

지정된 옵션을 사용하여 지정된 파일과 연결된 기본 앱을 시작합니다.

public:
 static IAsyncOperation<bool> ^ LaunchFileAsync(IStorageFile ^ file, LauncherOptions ^ options);
/// [Windows.Foundation.Metadata.Overload("LaunchFileWithOptionsAsync")]
 static IAsyncOperation<bool> LaunchFileAsync(IStorageFile const& file, LauncherOptions const& options);
[Windows.Foundation.Metadata.Overload("LaunchFileWithOptionsAsync")]
public static IAsyncOperation<bool> LaunchFileAsync(IStorageFile file, LauncherOptions options);
function launchFileAsync(file, options)
Public Shared Function LaunchFileAsync (file As IStorageFile, options As LauncherOptions) As IAsyncOperation(Of Boolean)

매개 변수

file
IStorageFile

파일입니다.

options
LauncherOptions

앱의 시작 옵션입니다.

반환

시작 작업입니다.

특성

예제

LauncherOptions.DisplayApplicationPickertrue로 설정된 [Launcher.LaunchFileAsync(IStorageFile, LauncherOptions) 메서드를 호출하여 사용자가 열기 대화 상자에서 파일에 대해 선택한 앱을 시작합니다.

async void DefaultLaunch()
{
   // Path to the file in the app package to launch
   string imageFile = @"images\test.png";

   var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);

   if (file != null)
   {
      // Set the option to show the picker
      var options = new Windows.System.LauncherOptions();
      options.DisplayApplicationPicker = true;

      // Launch the retrieved file
      bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
      if (success)
      {
         // File launched
      }
      else
      {
         // File launch failed
      }
   }
   else
   {
      // Could not find file
   }
}
Windows::Foundation::IAsyncAction MainPage::DefaultLaunch()
{
    // Get the app's installation folder.
    Windows::Storage::StorageFolder installFolder{ Windows::ApplicationModel::Package::Current().InstalledLocation() };

    Windows::Storage::StorageFile file{ co_await installFolder.GetFileAsync(L"Assets\\LockScreenLogo.scale-200.png") };

    if (file)
    {
        // Set the option to show the picker.
        Windows::System::LauncherOptions launcherOptions;
        launcherOptions.DisplayApplicationPicker(true);

        // Launch the retrieved file.
        bool success{ co_await Windows::System::Launcher::LaunchFileAsync(file, launcherOptions) };
        if (success)
        {
            // File launched.
        }
        else
        {
            // File launch failed.
        }
    }
    else
    {
        // Couldn't find file.
    }
}
void MainPage::DefaultLaunch()
{
   auto installFolder = Windows::ApplicationModel::Package::Current->InstalledLocation;

   concurrency::task<Windows::Storage::StorageFile^> getFileOperation(installFolder->GetFileAsync("images\\test.png"));
   getFileOperation.then([](Windows::Storage::StorageFile^ file)
   {
      if (file != nullptr)
      {
         // Set the option to show the picker
         auto launchOptions = ref new Windows::System::LauncherOptions();
         launchOptions->DisplayApplicationPicker = true;

         // Launch the retrieved file
         concurrency::task<bool> launchFileOperation(Windows::System::Launcher::LaunchFileAsync(file, launchOptions));
         launchFileOperation.then([](bool success)
         {
            if (success)
            {
               // File launched
            }
            else
            {
               // File launch failed
            }
         });
      }
      else
      {
         // Could not find file
      }
   });
}
async Sub DefaultLaunch()

   ' Path to the file in the app package to launch
   Dim imageFile = "images\test.png"

   Dim file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile)

   If file IsNot Nothing Then
      ' Set the option to show the picker
      Dim options = Windows.System.LauncherOptions()
      options.DisplayApplicationPicker = True

      ' Launch the retrieved file
      Dim success = await Windows.System.Launcher.LaunchFileAsync(file, options)

      If success Then
         ' File launched
      Else
         ' File launch failed
      End If
   Else
      ' Could not find file
   End If
End Sub

설명

호출 앱은 API가 호출될 때 사용자에게 표시되어야 합니다.

이 API는 ASTA 스레드(UI 스레드라고도 함) 내에서 호출해야 합니다.

또한 이 API는 시작할 수 있는 파일 형식에 몇 가지 제한을 적용합니다. 실행 코드(예: .exe, .msi 및 .js 파일)가 포함된 많은 파일 형식은 시작이 차단됩니다. 이 제한은 시스템을 수정할 수 있는 잠재적으로 악의적인 파일로부터 사용자를 보호합니다.

위의 이유로 인해 시작이 실패하면 API가 성공하고 비동기 작업에서 FALSE를 반환합니다. 위의 제한이 현재 시작에 적용되는지 여부를 쿼리할 수 없으므로 호출 앱은 시작이 성공했다고 가정해서는 안 되며 실패한 경우 대체 메커니즘을 제공해야 합니다. 가능한 해결 방법은 사용자에게 파일을 저장하도록 요청하고 사용자에게 바탕 화면에서 파일을 열도록 지시하는 것입니다.

사용자가 기본 앱을 시작하는 대신 앱을 선택할 수 있도록 하려면 LauncherOptions.DisplayApplicationPicker 속성을 설정합니다.

파일이 안전하지 않을 수 있다는 경고를 표시하려면 LauncherOptions.TreatAsUntrusted 속성을 설정합니다.

파일이 연결된 앱에 전달됩니다. 연결된 앱이 데스크톱 앱인 경우 셸 실행 메커니즘을 사용하여 파일이 전달됩니다.

추가 정보

적용 대상