To find out what makes your system freeze, you first need to deploy the Windows screw. What did Windows do when you experienced a hang?
To find this, you can take a core dump. How to get and analyze a core dump: here .
Depending on the results you get there, you need to decide if there is anything under your control that you can do about. Since you use a third-party library for writing, you can do little more than set the priority of the I / O , the priority of the stream per thread or process level. If you were provided with links to a specific CRT in the library, you could try creating your own custom version, for example. flush after each write to prevent the OS from writing to share only data in large chunks back to disk.
Edit1
It would be best to hide the device after each recording . This can cause the OS to clear any pending data and write the current pending write to disk without caching records to a certain amount.
The second best thing is to just wait after each recording to give the OS the ability to write pending changes, albeit a little back to disk after a certain amount of time.
If you go deeper into performance, you should try XPerf , which has a nice graphical interface and even shows you the call stack your process was hanging in. The Windows Team and many other MS commands use this tool to troubleshoot experience . The latest edition with many features comes with the Windows 8 SDK . But beware that Xperf only works with OS> Vista.
source share