[Solved] Streamreader locks file


StreamReader smsmessage = new StreamReader(filePath);

try
{
    FileInfo filenameinfo = new FileInfo(filePath);
    ....
    smsmessage = filenameinfo.OpenText();
    ...

You are initializing smsmessage twice, but only disposing one of those instances. The first line constructs a StreamReader, and then you overwrite your reference to that instance with the instance created by filenameinfo.OpenText(). That leaves you with an instance that no longer has any references and hasn’t been disposed. That instance might be holding a lock on the file and you have no guarantees on when it will be disposed. Even if it isn’t holding a lock, you should still fix this.

1

solved Streamreader locks file