Locked FlushAsync alternative in Windows Phone

  • lunes, 21 de mayo de 2012 15:21
     
      Tiene código

    Hello everyone,

    I have a code working on Windows 8 but I can't make it work on Windows phone :

    using (Stream requestStream = await request.GetRequestStreamAsync())
                using (StreamWriter writer = new StreamWriter(requestStream))
                {
                    await requestStream.WriteAsync(buffer, 0, buffer.Length);
                    await requestStream.FlushAsync();
                }

    The FLushAsync method doesn't exists in Windows Phone. I'm asking you if you know an alternative to this method.

    Thanks.

Todas las respuestas

  • miércoles, 23 de mayo de 2012 16:17
    Moderador
     
     Respondida

    Hi corbicorben-

    As a workaround, you could add your own extension method to Stream, e.g.

    public static Task FlushAsync(this Stream stream)
    {
        return Task.Factory.StartNew(() => stream.Flush());
    }

    That will at least allow the code to function and remain responsive.

  • viernes, 25 de mayo de 2012 14:32
     
     
    Thank you, I didn't know about the Factory property, it was blocking me a bit.