Autor Beitrag
gitta
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: Sa 11.06.05 19:59 
Hallo Zusammen,

ich habe ein Timer welcher eine Procedure aufruft.
Solange diese Procedure läuft, soll der Timer diese
Procedure nicht erneut aufrufen können. Aktuell mache
ich das so, das ich eine globale Boolen variable dafür hernehme.
Funktionieren tut es schon aber ich finde es ist nicht so
schön. Ich glaube den Begriff Semaphore in diesen Zusammenhang
schon mal gelesen zu haben.
Ich würde es besser finden wenn die Procedure selbst das händeln
könnte.

Hat jemand eine Idee?

Gruß Gitta
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 11.06.05 20:05 
Also ich finde das mit der Booleanvariable in Ordnung. Du meinst so, oder?

Global: var ProzLaeuft: Boolean;

Prozedur-Anfang:
ausblenden Delphi-Quelltext
1:
2:
if ProzLaeuft then exit;
ProzLaeuft := true;


Preozedur-Ende: ProzLaeuft := false;

AXMD
gitta Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: Sa 11.06.05 20:14 
user profile iconAXMD hat folgendes geschrieben:
Also ich finde das mit der Booleanvariable in Ordnung. Du meinst so, oder?

Global: var ProzLaeuft: Boolean;

Prozedur-Anfang:
ausblenden Delphi-Quelltext
1:
2:
if ProzLaeuft then exit;
ProzLaeuft := true;


Preozedur-Ende: ProzLaeuft := false;

AXMD


je genau so mache ich das.
Ich möchte globale Variablen vermeiden wo es nur geht.
Deshalb suche ich einfach nach einer besseren Lösung.

Gibt es sonst keine andere Möglichkeit?

Ach übrigens: den Timer innerhalb der Procedure anhalten is nich
weil er noch andere sachen macht.

Gruß Gitta


Zuletzt bearbeitet von gitta am Sa 11.06.05 20:34, insgesamt 1-mal bearbeitet
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 11.06.05 20:33 
Wieso willst du eigentlich erst die Prozedur aufrufen und dann prüfen, ob sie ihren Code vollständig ausführen darf oder nicht? Disable doch einfach den Timer. ;)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure DeineProcedure;
begin
Timer1.Enabled := False;
//CODE
Timer1.Enabled := True;
end;


;)
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 11.06.05 20:43 
Hast du irgendwo ein Application.Processmessages drin?
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 11.06.05 20:53 
user profile icondelfiphan hat folgendes geschrieben:
Hast du irgendwo ein Application.Processmessages drin?

Bin jetzt zwar nicht der Threadsteller, aber wieso fragst du? :eyes:
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 11.06.05 20:57 
Kann mir nicht vorstellen, dass ein Timer einfach so irgendwo reinfummelt, d.h. den Event doppelt startet.
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Sa 11.06.05 20:57 
alternativ kannst du auch mit criticalsections arbeiten
Suche im MSDN INITIALIZECRITICALSECTIONANDSPINCOUNT

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 11.06.05 20:59 
Naja, statt die WinAPIs kannst du auch indirekt die TCriticalSection benützen. Hast du mehrere Threads? Sonst kriegste n Deadlock; bzw. nicht ein Deadlock aber er wartet dann unendlich auf nichts würd ich meinen.
Das Problem ist wohl, dass du irgendwo ein Application.Processmessages drin hast, dort drin wird dann ein erneuter Timerevent gestartet.
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 11.06.05 21:02 
user profile icondelfiphan hat folgendes geschrieben:
Kann mir nicht vorstellen, dass ein Timer einfach so irgendwo reinfummelt, d.h. den Event doppelt startet.

Wieso doppelt startet? Es kann doch einfach sein, dass die procedure noch vom vorherigen Mal arbeitet und der Timer schon wieder auslöst.... :gruebel:
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 11.06.05 21:03 
Ne der wartet doch (es sei denn eben Application.p...).
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 11.06.05 21:07 
user profile icondelfiphan hat folgendes geschrieben:
Ne der wartet doch (es sei denn eben Application.p...).

Mhmm... Das ganze Prog wartet bis die procedure abgearbeitet ist... Klar... Danke! ;)
gitta Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: Sa 11.06.05 22:00 
user profile iconWeBsPaCe hat folgendes geschrieben:
user profile icondelfiphan hat folgendes geschrieben:
Ne der wartet doch (es sei denn eben Application.p...).

Mhmm... Das ganze Prog wartet bis die procedure abgearbeitet ist... Klar... Danke! ;)



ACHTUNG ein Timer wartet gans sicher nicht bis die Procedure durchgelaufen ist!!!
Deshalb verwendet man auch einen Timer. :wink:

Appication.Precessmessages habe ich zwar im mein Programm aber dieser
tangiert den Timer überhaupt nicht.

Gruß Gitta.
gitta Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: Sa 11.06.05 22:03 
user profile icondelfiphan hat folgendes geschrieben:
Naja, statt die WinAPIs kannst du auch indirekt die TCriticalSection benützen. Hast du mehrere Threads? Sonst kriegste n Deadlock; bzw. nicht ein Deadlock aber er wartet dann unendlich auf nichts würd ich meinen.
Das Problem ist wohl, dass du irgendwo ein Application.Processmessages drin hast, dort drin wird dann ein erneuter Timerevent gestartet.


Ich habe überhaupt kein Thread. Leider habe ich mich mit Threads noch nicht beschäftigt.

Gruß Gitta
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Sa 11.06.05 22:12 
user profile icongitta hat folgendes geschrieben:

Ich habe überhaupt kein Thread. Leider habe ich mich mit Threads noch nicht beschäftigt.
Gruß Gitta

ein timer ist nichts anderes als ein thread

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
gitta Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 47



BeitragVerfasst: Sa 11.06.05 22:18 
user profile iconretnyg hat folgendes geschrieben:

ein timer ist nichts anderes als ein thread


Ein Timer startet sich selbst in den angegebenen Interval.
Ist das auch mit Threads möglich?

Gruß Gitta
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 11.06.05 22:20 
Ein Timer ist doch kein Thread. Und natürlich liegt es an deinem Application.Processmessages, dass dein Event verschachtelt ausgeführt wird (muss nicht sein, wäre aber naheliegend)...
Ist auf jeden Fall meine Meinung.
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Sa 11.06.05 22:23 
jo, ein einfacher timer:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var timerenabled:boolean = true;

procedure timer1;  stdcall;
const mess : pchar = 'launched by timer'#0;
begin
  while timerenabled do begin
    messageboxA(0,mess,'',1);
    sleep(1000);
  end;
end;


procedure TForm1.Button2Click(Sender: TObject);
var tid: cardinal;
begin
 createthread(nil,0,@timer1,nil,0,tid);
end;


ne aufwendigere version würde bei jedem timerloop mit gettickcount prüfen, wieviel ms schon verstrichen sind und dies vom wert bei sleep (intervall) abziehen

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...


Zuletzt bearbeitet von retnyg am Sa 11.06.05 22:47, insgesamt 2-mal bearbeitet
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Sa 11.06.05 22:30 
user profile icondelfiphan hat folgendes geschrieben:
Ein Timer ist doch kein Thread.

ich hab das jetzt noch nicht mit dem debugger überprüft, aber wie sollte das programm, ohne einen thread zu benutzen, von selber zu einem gewissen zeitpunkt in den timerloop einsteigen, ohne die paralelle ausführung des "normalen" codes zu verhindern ?

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 11.06.05 22:36 
Der Timer "ist" ein Window und der Event wird mittels Message (WM_TIMER) ausgelöst. Der Timer läuft im selben Thread, deswegen gibt's ohne ProcessMessages auch keine verschachtelten Eventaufrufe.