[.net] Background File Verification

Started by
1 comment, last by DrGUI 18 years, 1 month ago
Hi I think it would take too long to make my own game file system using zip files or something, so I'm considering background verification of game files. I know it's pointless trying to stop really serious people but I'm sure this will stop 99% of people and give me some more experience with multithreading. The verification would be on a separate thread so I can make it sleep, as I obviously don't want it hogging half the CPU and slowing my game down. Pseudo code for my thread procedure would be something like this:

Get file path from main thread
Open the file to verify
while (bytes left to be read)
{
   Get whether app is closing, exit this thread (return) if it is (after closing file)
   Compute some simple checksum with the bytes, just xoring them maybe
   Sleep for 50ms or so...need to find a good value for this
}
Send checksum back to main thread (where it will be compared to what it should be), or an exception if one occured
Now I've done some asynchronous file IO in the past, apart from that I haven't really done any multithreading, though I know about the race condition and deadlocking. I'm obviously fine with opening the file and the checksum, I'm just not sure about the interaction of the threads. Would I just have a class with properties and methods that use 'lock(this)' to make them thread-safe? Thanks a bunch; I hope that's coherent, I need to go do more school work :(
Advertisement
Also, is there anything I can do if my verification thread is blocked on IO and I want to end it immediately, for instance if the app is closing down?
From using Thread.Abort would the ThreadAbort exception raised allow me to close the file before returning?

Thanks
I learnt what I need from the links given in the above thread 'How to use threads to iterate through file system?', thanks!

This topic is closed to new replies.

Advertisement