hi all,
Problem:I have a software, I have to handle system abrupt shutdown while in my software execution.

Description:
I am executing my software in windows xp. Every time to execute it will take ~45sec. While in software execution, i will create some temp files. In the execution process machine shutdowns abruptly ( due to power off) and after you start the machine i did not find my temp files in local machines!!!! :( I need these files to recover my software.)

My question is,
How/Where can i create/store the temp files such away that after abrupt shutdown and restart those files will be present in my machine!!!

Regards,
uday.

Dani AI

Generated

— the behavior you describe is almost always caused by writes sitting in the OS/disk cache when power was lost rather than actually reaching the physical disk. Saying “save regularly” (as suggested) is correct, but you must make those saves durable: open/write the file in a way that forces the OS to commit data and metadata to disk, or the file can disappear after an abrupt shutdown.

Concrete checklist and patterns to make temp files survive a crash:

  • Write to a persistent folder (user AppData or ProgramData) rather than a volatile place.
  • Don’t use FILE_ATTRIBUTE_TEMPORARY or FILE_FLAG_DELETE_ON_CLOSE for anything you intend to keep. Those flags encourage in-memory-only behavior.
  • Use write-through and explicit flushes: open the file for write with a write-through flag and call the OS flush routine after writing.

Example (Win32 API):

HANDLE h = CreateFileA(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
    FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, NULL);
WriteFile(h, buf, len, &dw, NULL);
FlushFileBuffers(h);    // force data+metadata to disk
CloseHandle(h);

C runtime / .NET hints:

fwrite(...); fflush(f); _commit(_fileno(f)); fclose(f);

or in .NET:

new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.WriteThrough);

Design notes: write incremental checkpoints frequently (every few seconds or after meaningful work), write to a “.tmp” file, FlushFileBuffers and close it, then atomically rename to the real filename (MoveFileEx/ReplaceFile). That reduces the window of data-at-risk. Also prefer NTFS (journaling) over FAT and consider UPS or disabling device write-caching (admin-level, performance tradeoff). On startup detect leftover .tmp files and recover from the last successful checkpoint.

This complements ’s “save regularly” point: saving only helps if the save actually reaches the disk.

Recommended Answers

All 3 Replies

Hi and welcome to Daniweb,
I am not sure what you have done, if you saved the files they should still be there if you did not save anything, they are lost forever. If saved programs or files disappeared try downloading and running Reuva,
http://www.piriform.com/recuva
But it will not find an unsaved file.
The answer to the last part of the question:- You can save them where ever you like, but they must be saved regularly, If you are using Office Word, it automatically saves files you are working on at a pre-set period. You can alter that time if you want to save more often.

doing sumpthing way over my head ,wow, post is like reading a riddle and trying to solve it .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.