private static void GetRequestStreamCallback(object state)
{
GlobalLog.Enter("FileWebRequest::GetRequestStreamCallback");
LazyAsyncResult asyncResult = (LazyAsyncResult)state;
FileWebRequest request = (FileWebRequest)asyncResult.AsyncObject;
try
{
if (request.m_stream == null)
{
request.m_stream = new FileWebStream(request, request.m_uri.LocalPath, FileMode.Create, FileAccess.Write, FileShare.Read);
request.m_fileAccess = FileAccess.Write;
request.m_writing = true;
}
}
catch (Exception e)
{
// any exceptions previously thrown must be passed to the callback
Exception ex = new WebException(e.Message, e);
GlobalLog.LeaveException("FileWebRequest::GetRequestStreamCallback", ex);
// if the callback throws, correct behavior is to crash the process
asyncResult.InvokeCallback(ex);
return;
}
// if the callback throws, correct behavior is to crash the process
asyncResult.InvokeCallback(request.m_stream);
GlobalLog.Leave("FileWebRequest::GetRequestStreamCallback");
}