Specifically will spawning a thread using the TPL Task.Factory.StartNew
:
Task.Factory.StartNew(() => {
File.ReadAllText(@"thisFile.txt");
});
Causing any issues, etc? There doesn't appear to be any mention of thread safety on the MSDN resource
It's in a SOAP web service environment.
Ps Please, I don't want to know about the pro's and cons of using a Task in a web environment. I'm fully aware of these issues, please, just take it for granted that in my case this model is justified, thanks.
It's fine - assuming nothing's writing to the file at the same time, in which case you may not be able to open the file (or might see partial writes).
As per the documentation of File
:
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
(Not that there can be any instance methods, as it's a static class...)
See more on this question at Stackoverflow