Einzelnen Beitrag anzeigen

Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.768 Beiträge
 
Delphi 10.4 Sydney
 
#4

AW: Handle count erhöht sich permanent

  Alt 22. Okt 2014, 12:12
Hallo TiGü,

ich hoffe der Code ist relevant genug.
Ich sehe darin nichts auffälliges..

Delphi-Quellcode:
  TThreadTask = class(TThread)
    protected
      procedure onTerminate(sender: TObject);
    private
      fDevice: TDevice;
      fTask: TTask;
      fLogger: TLogger;
    public
      constructor create(device: TDevice; task: TTask);
      destructor Destroy; override;
      procedure Execute; override;
  end;
Delphi-Quellcode:
constructor TThreadTask.create(device: TDevice; task: TTask);
begin
  inherited create(true);
  freeOnTerminate := false;
  fLogger := TLogger.instance;
  fDevice := TDevice.create;
  fDevice.id := device.id;
  fDevice.name := device.name;
  fDevice.powerSourceId := device.powerSourceId;
  fTask := task;
  inherited onTerminate := onTerminate;
end;
Delphi-Quellcode:
destructor TThreadTask.Destroy;
begin
  freeAndNil(fDevice);
end;
und die Execute Routine

Delphi-Quellcode:
procedure TThreadTask.Execute;
begin
if assigned(fDevice) then
  begin
    case fTask of
      powerState: begin
                    try
                      fDevice.getDevicePowerState; //snmp Abfrage
                      case fDevice.powerState of
                        true: fLogger.add(6,format('Scan finished for: <%s - %s>',[fDevice.name, 'on']));
                        false: fLogger.add(6,format('Scan finished for: <%s - %s>',[fDevice.name, 'off']));
                      end;
                    except
                      on E: Exception do
                        begin
                          fLogger.add(1,format('Error in power-state query: %s',[E.Message]));
                        end;
                    end;
                  end;
      powerOn: begin
                 try
                   fDevice.powerOn;
                 except
                   on E: Exception do
                     fLogger.add(1,format('Error in power-on operation: %s',[E.Message]));
                 end;
               end;
      powerOff: begin
                  try
                    fDevice.powerOff;
                  except
                    on E:Exception do
                      fLogger.add(1,format('Error in power-off operation: %s',[E.Message]));
                  end;
                end;
    end;
  end;
end;
Klaus
  Mit Zitat antworten Zitat