Einzelnen Beitrag anzeigen

venice2
(Gast)

n/a Beiträge
 
#13

AW: Event bei Minutenwechsel der Windows-Uhr?

  Alt 30. Okt 2022, 16:26
Ich verwende für sowas SetWaitableTimer in Verbindung mit Thread und WaitForSingleObject.
Aber man kann es auch übertreiben.

Delphi-Quellcode:
function MySetWaitableTimer(hTimer: THandle;
                            var lpDueTime: TLargeInteger;
                            lPeriod: longint;
                            pfnCompletionRoutine: TFNTimerAPCRoutine;
                            lpArgToCompletionRoutine: Pointer;
                            fResume: BOOL): BOOL;
                            stdcall; external 'kernel32.dllname 'SetWaitableTimer';
Kleiner Ausschnitt..
Delphi-Quellcode:
constructor TVisDataThread.Create(var DataReadyMsg: HWND; var MemPointer: Pointer);
begin

  inherited Create(True);

  FDriveThreadId := 0;

  FShareMemPointer := GetBufferAddress;
  MemPointer := FShareMemPointer;
  FVisTimer := CreateWaitableTimer(nil, False, nil);
  if FVisTimer <> 0 then
  begin
    DataReadyMsg := FDataReadyMsg;
    FDelayMS := 0;
    FModuledelayMs := 0;
    FDelayMSChanged := False;
    FThreadReady := True;
  end;

end;
Delphi-Quellcode:
procedure TVisDataThread.Execute;
const
  _SECOND = 10000000;
var
  qwDueTime: Int64;
  liDueTime: _LARGE_INTEGER;
  ErrMsg: string;
begin

  if FVisTimer = 0 then
    Exit;

  // Create a negative 64-bit integer that will be used to
  // signal the timer 1/4 seconds from now.
  qwDueTime := -1 * (_SECOND div 4);

  // Copy the relative time into a LARGE_INTEGER.
  liDueTime.LowPart := DWORD(qwDueTime and $FFFFFFFF);
  liDueTime.HighPart := longint(qwDueTime shr 32);
  if MySetWaitableTimer(FVisTimer, // handle to a timer object
                        TLargeInteger(liDueTime), // when timer will become signaled
                        FDelayMS, // periodic timer interval
                        nil, // pointer to the completion routine
                        nil, // data passed to the completion routine
                        False {flag for resume state}) then
    // Following sentences are repeated every FDelayMS interval all the time from initial
    // start up to program end.
    repeat
      // We need to re-adjust timer interval according to the parameter "DelayMS" of vis plug-in.
      // (in case we exchange vis plug-ins)
      if FDelayMSChanged then
      begin
        FDelayMSChanged := False;
        CancelWaitableTimer(FVisTimer);
        MySetWaitableTimer(FVisTimer, TLargeInteger(liDueTime), FDelayMS, nil,
          nil, False);
      end;

      if WaitForSingleObject(FVisTimer, 1000 {1sec}) = WAIT_OBJECT_0 then
      begin
        DoOnVisTimer;
      end else
        Terminate;

      SuspendIfHalted;
    until Terminated
  else
  begin
    ErrMsg := SysErrorMessage(GetLastError);
    ShowErrorMsgBox(ErrMsg);
    Terminate;
  end;
end;
  Mit Zitat antworten Zitat