How to use SYSTEM function for specified time
-
how to use system API for given time some times a when i call system api, my computer hangs and i need to reboot can i use for given time
The API function [SetTimer ] executes a function every x milliseconds or any given time. MFC version [here]. Console example: The following console program works like this: It sets a timer using
SetTimer
then loops in a message loop. The message loop receives and processesWM_TIMER
messages and the timer callback also is called for each time interval. Simply put the stuff you want done in theTimerProc()
function.#define STRICT 1
#include #include VOID CALLBACK TimerProc(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime)
{
//put the stuff you want done in herecout << "Doing stuff Time: " << dwTime << '\n';
cout << "--------------------------------------------------\n" ;
cout.flush();
}int main(int argc, char *argv[], char *envp[])
{
int Counter=0;
int usage_Time_millisec=500;
MSG Msg;UINT TimerId = SetTimer(NULL, 0, usage\_Time\_millisec, &TimerProc); //bind TimerProc() to SetTimer() cout << "TimerId: " << TimerId << '\\n';
if (!TimerId) return 16;
while (GetMessage(&Msg, NULL, 0, 0))
{
++Counter;
if (Msg.message == WM_TIMER)
cout << "Doing stuff Counter: " << Counter << "; timer message\n";
else
cout << "Doing stuff Counter: " << Counter << "; message: " << Msg.message << '\n';
DispatchMessage(&Msg);
}KillTimer(NULL, TimerId);
return 0;
}
-
how to use system API for given time some times a when i call system api, my computer hangs and i need to reboot can i use for given time
MKC002 wrote:
how to use system API for given time
What exactly do you mean by this; which API and what time?
MKC002 wrote:
some times a when i call system api, my computer hangs and i need to reboot
Perhaps if you show an extract of the code that does this we may be able to help.
MKC002 wrote:
can i use for given time
Use what and for what time - time of day, time interval, ...?
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
MKC002 wrote:
how to use system API for given time
What exactly do you mean by this; which API and what time?
MKC002 wrote:
some times a when i call system api, my computer hangs and i need to reboot
Perhaps if you show an extract of the code that does this we may be able to help.
MKC002 wrote:
can i use for given time
Use what and for what time - time of day, time interval, ...?
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
our server maintains large amount of data. Everyday new files/folders created on it. A serevice set some special properties for files/folders. One service checkes if some property does not exist in file/folder then move the file to another location for further processing. Here one service call GetFileAttributes and GetVolumeInformation for disk where file will be move. From this function we get volume label and other information to store in database. Sometimes system hangs and i need to reboot. I noticed system hangs due to GetVolumeInformation. So, can i set time limit for this function. If after given time i dont get volume label then move the file to another disk.
-
our server maintains large amount of data. Everyday new files/folders created on it. A serevice set some special properties for files/folders. One service checkes if some property does not exist in file/folder then move the file to another location for further processing. Here one service call GetFileAttributes and GetVolumeInformation for disk where file will be move. From this function we get volume label and other information to store in database. Sometimes system hangs and i need to reboot. I noticed system hangs due to GetVolumeInformation. So, can i set time limit for this function. If after given time i dont get volume label then move the file to another disk.
It's more important to discover why the system hangs on this function; perhaps it is trying to access a network disk and you are having network problems, or the drive is failing. You could also move this code into a background thread and then kill it after a fixed time interval from your main thread.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
It's more important to discover why the system hangs on this function; perhaps it is trying to access a network disk and you are having network problems, or the drive is failing. You could also move this code into a background thread and then kill it after a fixed time interval from your main thread.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
Thanks for your reply. To play with thread is little difficult. Please give any link to kill thread which is safe and does not result in any type of crash.
MKC002 wrote:
Please give any link to kill thread which is safe and does not result in any type of crash.
You do realise what you are asking! How can I possibly know what code could be added to your program that will not crash it, even if I could be bothered to go and look for such a link? You are the developer it's up to you to do the work.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman