Sign in to follow this  

[.net] Background File Verification

This topic is 4300 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 :(

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4300 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this