Well I suggest having a look at synchronization objects. Mutex, Critical section and semaphore are three methods that you can use to make sure your operations are threadsafe.