Autor Beitrag
Stoffel1984
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 219

Win NT, Win 2000
D6 Prof
BeitragVerfasst: Do 27.05.04 14:11 
Hallo,

ich rufe in meinem Projekt eine andere Datei mit Parametern auf.
Da ich den Exitcode des Programms brauche geschieht dies mit

GetExitCodeProcess(ProcessInf.hProcess, dwRet);

Beim Aufruf dieses Programms (Fremdsoftware für einen Internetversand)
wird mein Projekt tierisch langsam, verliert den Focus und der Mauszeiger hängt.
Wie kann ich das umgehen? An fehlender Rechenpower kanns nicht liegen, da wenn ich die Exe normal starte (also nicht aus meinem Programm heraus) auch nix hängen bleibt.

Vielleicht habt ihr ne Idee zu meinem Code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
function RunExe(Parameter: PChar): string;
var
  path :string;
  StartupInf: STARTUPINFO;
  dwRet: DWORD;
begin
  path := FindExe('Programm')+ '\versand.exe';
  FillChar(StartupInf, SizeOf(StartupInf), #0);
  StartupInf.cb := SizeOf(StartupInfo);
  StartupInf.dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
  StartupInf.wShowWindow := SW_SHOW;

  if CreateProcess(PChar(path),Parameter, nil, nil, False,
    NORMAL_PRIORITY_CLASS, nil, nil, StartupInf, ProcessInf) then
    WaitForSingleObject(ProcessInf.hProcess, 60000);
    GetExitCodeProcess(ProcessInf.hProcess, dwRet);

  result := IntToStr(dwRet);
end;


Danke Stoffel
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 27.05.04 19:32 
1) fehlt da ein begin-end-Block bei deiner if-Abfrage
2) solltest du das Process-Handle schließen wenn dus nicht mehr brauchst (CloseHandle)
3) wartest du 6 sek. lang auf das Ende des Prozesses und während dieser 6 sek. ist dein Thread schlafen gelegt.. reagiert also auf nichts mehr..

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Stoffel1984 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 219

Win NT, Win 2000
D6 Prof
BeitragVerfasst: Fr 28.05.04 07:48 
Danke Motzi...

das mit den 60 (!) Sekunden hat den Hintergrund, dass wenn der Aufruf der Exe nicht nach 60 (!) Sek. abgeschlossen ist ich weitergehe und dann einen Fehler bringe.
Gibt es da keine andere Möglichkeit die 60 Sek auf das Ende zu warten - jedoch ohne Focusverlust und "einfrieren" des Fensters? Wenn ichs über ShellExecute aufrufe geht das ja auch...nur eben ohne Exitcode und diesen brauch ich nunmal zwingend...

Keiner ne Idee?

Stoffel
KidPaddle
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 351

WinXP,Linux
D7 Prof, XE7
BeitragVerfasst: Fr 28.05.04 08:06 
Pack den Aufruf in einen Thread. In einer Schleife prüfst Du, ob der Thread noch läuft und rufst innerhalb dieser Schleife Application.ProcessMessages auf. Damit friert dein Programm nicht mehr ein und Du kannst Dir jederzeit den Focus zurück holen.

Gruß
KidPaddle
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Fr 28.05.04 10:48 
Hoppla.. stimmt, 60sec.. :oops:
Entweder über einen Thread oder mit einer Schleife:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
  if CreateProcess(PChar(path),Parameter, nil, nil, False,
    NORMAL_PRIORITY_CLASS, nil, nil, StartupInf, ProcessInf) then
    try
      for i := 1 to 600 do
        if WaitForSingleObject(ProcessInf.hProcess, 100) = WAIT_TIMEOUT then
          Application.ProcessMessages;
        else
        begin
          GetExitCodeProcess(ProcessInf.hProcess, dwRet);
          Result := IntToStr(dwRet);
          Exit;
        end;
      Result := 'Process not terminated within 60 secconds';
    finally
      CloseHandle(ProcessInf.hProcess);
      CloseHandle(ProcessInf.hThread);
    end;

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!