DosStopTimer

From EDM2
Revision as of 19:23, 16 June 2018 by Ak120 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Stops an asynchronous timer.

Syntax

DosStopTimer(htimer)

Parameters

htimer (HTIMER) - input 
The handle of the timer to stop.

Return Code

ulrc (APIRET) - returns
DosStopTimer returns one of the following values:
  • 0 NO_ERROR
  • 326 ERROR_TS_HANDLE For a full list of error codes, see Errors.

Remarks

DosStopTimer stops either a repeated-interval timer (started by DosStartTimer), or a single-interval timer (started by DosAsyncTimer).

When DosStopTimer is called, no assumption can be made about the state of the event semaphore that is associated with the timer. If the application is going to reuse the semaphore in conjunction with another timer, it should issue DosResetEventSem to ensure that the semaphore is in the "reset" state before starting the timer.

Example Code

This example sets up a periodic interval timer of 2 seconds, lets it run for a while, and finally stops it.

 #define INCL_DOSSEMAPHORES   /* Semaphore values */
 #define INCL_DOSDATETIME     /* Timer support    */
 #define INCL_DOSERRORS       /* DOS error values */
 #include <os2.h>
 #include <stdio.h>

 int main(VOID) {

 HEV     hevEvent1     = 0;                   /* Event semaphore handle    */
 HTIMER  htimerEvent1  = 0;                   /* Timer handle              */
 APIRET  rc            = NO_ERROR;            /* Return code               */
 ULONG   ulPostCount   = 0;                   /* Semaphore post count      */
 ULONG   i             = 0;                   /* A loop index              */

    rc = DosCreateEventSem(NULL,           /* Unnamed semaphore            */
                           &hevEvent1,     /* Handle of semaphore returned */
                           DC_SEM_SHARED,  /* Indicate a shared semaphore  */
                           FALSE);         /* Put in RESET state           */
    if (rc != NO_ERROR) {
        printf("DosCreateEventSem error: return code = %u\n", rc);
        return 1;
    }

    rc = DosStartTimer(2000L,              /* 2 second interval            */
                       (HSEM) hevEvent1,   /* Semaphore to post            */
                       &htimerEvent1);     /* Timer handler (returned)     */
    if (rc != NO_ERROR) {
        printf("DosStartTimer error: return code = %u\n", rc);
        return 1;
    }

    for (i = 1 ; i < 6 ; i++) {

      rc = DosWaitEventSem(hevEvent1,15000L); /* Wait 15 seconds for timer */
      if (rc != NO_ERROR) {
          printf("DosWaitEventSem error: return code = %u\n", rc);
          return 1;
      }

      rc = DosResetEventSem(hevEvent1,       /* Reset the semaphore         */
                            &ulPostCount);   /* And get count (should be 1) */
      if (rc != NO_ERROR) {
          printf("DosWaitEventSem error: return code = %u\n", rc);
          return 1;
      }

      printf("Iteration %u: ulPostCount = %u\n", i, ulPostCount);

    } /* for loop */

    rc = DosStopTimer(htimerEvent1);       /* Stop the timer             */
    if (rc != NO_ERROR) {
        printf("DosCloseEventSem error: return code = %u\n", rc);
        return 1;
    }
    rc = DosCloseEventSem(hevEvent1);      /* Get rid of semaphore       */
    if (rc != NO_ERROR) {
        printf("DosCloseEventSem error: return code = %u\n", rc);
        return 1;
    }

 return NO_ERROR;
}

Related Functions