c# - How to release file handle by aspnet_wp.exe -


i have wcf service hosted in iis, service generates xml file using following code:

xmlserializer serializer = new xmlserializer(typeof(batch)); using (textwriter textwriter = new streamwriter(configurationmanager.appsettings["sftpdirectorypath"] + "\\" + bundle.name.replace("dat", "xml"))) {     serializer.serialize(textwriter, batch);     textwriter.close(); } 

after xml file written on disk, if try change content of file or if try delete file, error message file being used process, close programs using file. downloaded app called "ofview" shows process holds handle on file , locking it. shows aspnet_wp holding lock on xml file. ofview allows me release handle, can change file or delete it.

my question is: how can release handle programmatically, once done writing file in code? missing something? help.

if have code posted, file handle released after call textwriter.close() - try putting same code in dummy project , step through execution. should receive error when trying delete file before textwriter.close() called, should able delete file right after textwriter.close().

is there other i/o in service?

edit

not sure whether help, try flushing stream before close call:

serializer.serialize(textwriter, batch); textwriter.flush(); textwriter.close(); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -