Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is ASP.NET HttpPostedFile.SaveAs a blocking call?

Tags:

c#

asp.net

I was wondering whether HttpPostedFile.SaveAs function in ASP.NET C# is a blocking call.

like image 225
Zulfi Tapia Avatar asked Mar 01 '11 13:03

Zulfi Tapia


1 Answers

Yes (snippet from reflector):

FileStream s = new FileStream(filename, FileMode.Create);
try
{
    this._stream.WriteTo(s);
    s.Flush();
}
finally
{
    s.Close();
}

It does not use BeginWrite and EndWrite so it is blocking.


UPDATE

If you are wondering what _stream.WriteTo(s); does:

internal void WriteTo(Stream s)
{
    if ((this._data != null) && (this._length > 0))
    {
        this._data.WriteBytes(this._offset, this._length, s);
    }
}

which is again blocking.

like image 115
Aliostad Avatar answered Oct 20 '22 05:10

Aliostad