Okay, so I'm new to C#, and when I say new, I mean I only really started looking at it yesterday, anyway, I'm currently making a fun little application, however, I have an automated mechanic that will simply write read and write .txt files.
Anyway, I'm not 100% sure what it could be, I think it could possibly be that I'm using the same StreamWriter or something?
FYI. I haven't provided any code on purpose, because of the fact that I don't know if there's an easy solution here, or if you will have to look at the code to debug it, if you need me to provide you with code examples, it's no problem what so ever.
Code would be really helpful, but let me try to explain what is PROBABLY going on. We can't be sure if this is the actual problem.
There is something called file locking and this is done on a filesystem level iirc, but the implementation is done in code, probably in the stream library you're using. Files can be locked in certain ways, like exclusive or shared. This changes the access modifiers for that file, for the duration you're using that specific file. In your 'new-ness' to programming, it might be you're actually accidentally locking the file and then not releasing it in the correct way, which inhibits you from then using it again later on. This is what might be happening.
Another reason I can think of is that another instance of your application is still running in the background. I don't have a lot of experience with C# myself but Visual Studio might have lost communication with the process or whatever and for that reason it is not able to exit it, which might cause this exception.
Thank you for your time, seriously, and I feel like an idiot right now, but after a few more google-ing attempts, I got there in the end. I managed to find my way around it, all I was doing wrong was that I wasn't using the .Close method when I was creating a file, so the file was in theory always being used by another process. Or at least I'm pretty sure that's all that was wrong, after adding that, it worked fine to say the very least, hence my conclusion.
Yep that would probably have been the issue, I have been there before with both Java and C#, like I said
releasing a file is done with .Close() and should always be called. Some libraries have an Autoclose feature but I always close it manually anyways, reducing the risk of concurrency errors. Learning the hard way is always the most effective one because now you'll never forget haha. I hope this helped and now you can .Close() this topic ;)