Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:57:36+00:00 2026-06-08T23:57:36+00:00

I have method with signature I cannot change. It should be protected override void

  • 0

I have method with signature I cannot change. It should be

protected override void OnInitialize()

Using Windows 8 Metro API I need to check if file exists and read it, inside this NoSignatureChange method.
Using PlainOldCSharp, I would write something like

protected override void OnInitialize()
{
  ...
  try
  {
    var file = folder.OpenFile(fileName);
    fileExists=true;
  }
  catch(FileNotFoundException)
  {
    fileExists=false
  }
}

Remember, in Windows 8 API only way to check if file exists is handling FileNotFoundException
Also, in Windows 8 API all FileIO API is async, so I have only file.OpenFileAsync method.

So, the question is: How should I write this code using folder.OpenFileAsync method in Windows 8 API without changing signature of containing method

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:57:38+00:00Added an answer on June 8, 2026 at 11:57 pm

    You can still make a void method async:

    protected async void CannotChangeSignature()
    {
        ...
    }
    

    Valid return types for an async method are:

    • void
    • Task
    • Task<T>

    However, if you want to make it actually block, then you’re basically fighting against the platform – the whole point is to avoid blocking.

    You say you can’t change the signature – but if you’re relying on this blocking then you’ve got to change the way you approach coding.

    Ideally you should change the signature to Task<bool>:

    protected async Task<bool> CannotChangeSignature()
    {
      ...
      try
      {
        await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
        return true;
      }
      catch(FileNotFoundException)
      {
        return false;
      }
    }
    

    EDIT: If you really need a blocking one, you’ll just have to call AsTask().Wait(), catch the AggregateException and check whether it contains a FileNotFoundException. It really is pretty horrible though… can you not design around this so that it doesn’t need to be blocking? For example, start checking for the file, and show an error (or whatever) if and when you find it doesn’t exist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a method signature like this: protected override void Initialize(params object[] parameters)
I have the following method signature. I cannot change it (i.e. I cannot change
I have a method with the following signature: void MyMethod(Delegate d){}; void MyMethod(Expression exp){};
If I have a method signature like public string myMethod<T>( ... ) How can
I have a method that is receiving more than one parameter. The method signature
I have the following method signature, how do i convert it to be a
Suppose I have the following method signature int f (int[] values) and I call
I have a method with this signature, and another method that will be the
I have a method with this signature: IEnumerable<string> GetCombinations(string s, int length) And I
I have a general Java method with the following method signature: private static ResultSet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.