Asynchronous file writes
We've now seen how to asynchronously access the database and a web service. Another area where asynchronous coding may bring performance benefits is writing files to disc after they have been uploaded using the FileUpload
control.
Synchronous version
You'll find this code in the downloaded code bundle in the folder ThreadStarvation_FileWrite_Sync
. When you open the website in Visual Studio, you'll find that it stores uploaded files in a folder images
. When you publish the website, to enable the website to write files into that folder, give user IIS_IUSRS modify permission to that folder:
1. Right-click on the images folder. Click on Properties | Security | Edit.
2. Select IIS_IUSRS in upper-pane (add it if it isn't shown).
3. Check the Allow checkbox in the Modify row and click on OK.
Using a FileUpload
control synchronously is pretty easy. You put it on a .aspx
page, together with a button to initiate the actual upload and a label control for error messages, shown as...