1

I want to make an MFC app which leave a thread/process running in the background all the time that keeps track of something like hard disk size.

Whenever the hard disk size goes beyond lets say 90% it shows a warning dialog (also MFC dialog of same app).

I am not sure how to do it.

I tried the windows service option, but it doesn't seem much reliable to me , as most of the times, the service is not successfully installed, or if installed it doesn't get started successfully.

What other options do I have to achieve it?

Any help is appreciated.

foobar
  • 2,887
  • 2
  • 30
  • 55
  • 2
    If your service isn't installed or running properly, you need to fix your program. I've made plenty of service programs, all installing and running fine for long periods of time. – Some programmer dude Apr 11 '14 at 11:26
  • Of course you can always make a normal program, and put it in the system autostart folder. Then you can even make an icon for it in the system-tray. – Some programmer dude Apr 11 '14 at 11:28
  • Other than that, please take some time to read [the help pages](http://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). And more importantly, please read [the Stack Overflow question checklist](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist). You might also want to learn how to create a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Some programmer dude Apr 11 '14 at 11:30
  • @user2681573, unless you have a compelling reason to write a windows service in C++ and to use MFC for notifications, I would suggest taking a look at C#. My answer here provides step-by-step instructions for creating and installing a C#-based service. http://stackoverflow.com/questions/593454/easiest-language-for-creating-a-windows-service/593803#593803 – Matt Davis Apr 12 '14 at 03:02
  • @user2681573, here is a CodeProject article for writing an application to interact with the service. http://www.codeproject.com/Articles/742494/General-Windows-Service-Debugged-as-Console-Applic – Matt Davis Apr 12 '14 at 03:03

1 Answers1

1
  1. Create a worker thread which keep on monitoring the disk space.
  2. Create a user defined message in the main thread and provide a handler for it
  3. When disk space goes more than 90%, Post a message (Post the user defined message that you created)
  4. From the main thread handler for the user defined message "Display the warning message"

Note: Services are not suitable for this task as they don't like user interactions.

Sivaraman
  • 438
  • 2
  • 9
  • 1
    There's a flag that can be set that allows services to interact with the desktop, like showing a message box. – Some programmer dude Apr 11 '14 at 11:28
  • Oh! I am not aware of it. What I specified is bookish stuff. If You already did that I will go with U. Thanks for specifying Joachim Pileborg. – Sivaraman Apr 11 '14 at 11:35
  • @Sivaraman So a worked thread will keep on running in the background even between application exits and system restarts ? – foobar Apr 11 '14 at 11:37
  • No, a worker thread runs only when the app is running. If your app is added to the startup folder it will start when the system starts. – ScottMcP-MVP Apr 11 '14 at 13:13
  • 1
    @Joachim Pileborg, the days of allowing services to interact with the desktop died with Windows Vista. Refer to the accepted answer here: http://superuser.com/questions/415204/how-do-i-allow-interactive-services-in-windows-7 – Matt Davis Apr 12 '14 at 02:58