damos 0 Posted September 7, 2020 (edited) Hi am new Onomnithread library , and i examine the TwoFish example i understand how Working Schedule works , My question is how can i restart the FWorker.Schedule if database is not connected (for example unstable network) after a few seconds until database be connected ??? In the main thread a create an instance of TComclass procedure TMainform.Button1Click(Sender: TObject); begin acom:= TComclass.Create(nil); acom.OpenConnection(format(common.PostgresConnection,['wwwwwwwww','wwwwwwwwww','wwww']), procedure (Sender: TObject; FatalException: Exception) begin if assigned(FatalException) then Begin if FatalException is EDAerror then Begin if (FatalException as EDAerror).ErrorCode=0 then Errormessage.Caption:=FatalException.message else Errormessage.Caption:=FatalException.message+inttostr((FatalException as EDAerror).ErrorCode); End else Errormessage.Caption:=FatalException.message; // ShowMessage('Failed to connect to the database! ' + FatalException.Message) end else Begin Errormessage.Caption:='ComServer database connected' ; End; end); end; Declaration of Tcomlass procedure TComclass.OpenConnection(const databaseName: string; onConnectionOpen: TNotify); begin FWorker.Schedule( FWorker.CreateWorkItem(databaseName), FWorker.Config.OnExecute(ConnectToDatabase).OnRequestDone( procedure (const Sender: IOmniBackgroundWorker; const workItem: IOmniWorkItem) begin if assigned(onConnectionOpen) then Begin onConnectionOpen(Self, workItem.FatalException); if workItem.IsExceptional then Begin fdataModule.lisconnection.ConnectString := workItem.Data.AsString; fdataModule.lisconnection.Connected := true; end; end; end )); end; procedure TComclass.ConnectToDatabase(const workItem: IOmniWorkItem); var dataModule: TdmComdb; begin dataModule := (workItem.TaskState.AsObject as TdmComdb); dmComdblock.Acquire; //probably only necessary when using InterBase driver dataModule.lisconnection.ConnectString := workItem.Data.AsString; dataModule.lisconnection.Connected := true; try finally dmComdblock.Release; end; end; Edited September 7, 2020 by damos Share this post Link to post