srhartone
Tue Jun 19 08:15:02 CDT 2007
Ah, I did just notice you mentioned it was a command-line app. Even still,
I'd still do my suggestions without the event of course.
--
Simon Hart
http://srhartone.blogspot.com
"Steve B." wrote:
> This is only a "simple" console application that has no ui (with the
> exception of the cursor).
>
> Steve
> "Simon Hart" <srhartone@yahoo.com> wrote in message
> news:229B4A76-2574-4D63-B44D-6A91EE9ADC27@microsoft.com...
> > That code will work and I am assuming method SystemIdleTimerReset() is
> > calling SHIdleTimerReset in aygshell.dll. I am also assuming the code you
> > posted is in the UI layer because of changing the cursor to wait would
> > generally take place in the UI layer.
> >
> > You haven't posted the DoTheLongOperation() method but I will assume it is
> > not running in its own separate worker thread because you set the cursor
> > to
> > wait.
> >
> > So I am assuming a lot of things!! ;)
> >
> > The way I would of coded it would be simpler and getting rid of the timer.
> > Moving all that logic from the UI. I would wrap the DoTheLongOperation up
> > into the business layer which would create a new worker thread to do the
> > work. This enables control to return to the UI preventing it from locking
> > up
> > for the whole process. Part of this business procedure would call
> > SHIdleTimerReset. I would lose the wait cursor and possibly create an
> > event
> > which the UI would subscribe to which tells the UI when the process has
> > finished.
> >
> > --
> > Simon Hart
> >
http://srhartone.blogspot.com
> >
> >
> > "Steve B." wrote:
> >
> >> Hi,
> >>
> >> In one of our applications, we have a long process that can take up to 10
> >> minutes.
> >> During this time, I don't want the device to enter sleep mode.
> >> The process is embedded in a command line application and I wrote this
> >> code
> >> :
> >>
> >> uint timerID = 0;
> >> int _tmain(int argc, _TCHAR* argv[])
> >> {
> >> timerID = SetTimer(NULL, 0, 5000, &(TimerProc));
> >> SetCursor(LoadCursor(NULL, IDC_WAIT));
> >>
> >> DoTheLongOperation();
> >>
> >> SetCursor(NULL);
> >> KillTimer(NULL, timerID);
> >> return 0;
> >> }
> >>
> >> void CALLBACK TimerProc(
> >> HWND hwnd,
> >> UINT uMsg,
> >> UINT idEvent,
> >> DWORD dwTime
> >> )
> >> {
> >> SystemIdleTimerReset();
> >> timerID = SetTimer(NULL, 0, 5000, &(TimerProc));
> >> }
> >>
> >> I wonder if this pattern is correct.
> >>
> >> Thanks in advance for any feedback!
> >> steve
> >>
> >>
> >>
>
>
>