Autor Beitrag
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: So 17.11.02 16:36 
Hallo!

Ich habe ein Programm geschrieben, in dem ich meine Internetverbindungen speichern kann und alle nacheinander wählen kann. Diese habe ich geschrieben, damit ich Sonntags kostenlos ins Internet komme.
Um eine Verbindung inst Internet zu erstellen, benutze ich die API RasDial. Damit habe ich auch keine Probleme. Ein Problem bekomme ich erst dann, wenn eine Verbindung aus irgendwelche Gründen nicht zustande kommt. Dann muss ich mit RasHangUp die Verbindung wieder beenden. Das Problem ist hierbei, dass nach diesem Befehl Windows "eine Weile" benötigt um den Port zu schliessen. Die Online-Hilfe (zum Befehl RasHangUp) rät folgendes:
Zitat:
An application should not call RasHangUp and then immediately exit. The connection state machine needs time to properly terminate. If the system prematurely terminates the state machine, the state machine may fail to properly close a port, leaving the port in an inconsistent state. A simple way to avoid this problem is to call Sleep(3000) after returning from RasHangUp; after that pause, the application can exit. A more responsive way to avoid the problem is, after returning from RasHangUp, to call RasGetConnectStatus(hrasconn) and Sleep(0) in a loop until RasGetConnectStatus returns ERROR_INVALID_HANDLE.
Die erste Möglichkeit, also Sleep(3000) möchte ich nicht nutzen, da diese Zeit bei mir manchmal nicht reicht und manchmal das ganze unnötig verlängert. Die zweite Möglichkeit klappt bei mir erst gar nicht. Ich habe folgenden Quelltext geschrieben:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
var
  Status: TRasConnStatusA;
begin
  repeat
    Application.ProcessMessages;
  until RasGetConnectStatus(hRas, Status) = ERROR_INVALID_HANDLE;
Nun hoffe ich, dass mir jemand sagen kann, was ich falsch gemacht habe oder dass jemand eine andere Lösung kennt!

Ich danke für eure Hilfe!
wulfskin

_________________
Manche antworten um ihren Beitragszähler zu erhöhen, andere um zu Helfen.