Home
Top.Mail.Ru Yandeks.Metrika
Forum: "WinAPI";
Current archive: 2004.12.12;
Download: [xml.tar.bz2];

Down

Create and end stream Find similar branches


S@shka ©   (2004-10-30 23:45) [0]

People, here help me to finally enter the next question.
There is a window application, on Form.Create it is worth creating a stream
by calling BeginThread (...);
Further, as I understand it, let's say the thread has completed its work
we notified the main window, for example, PostMessage (Form1.Handle ...).
In the handler, call CloseHandle (ThreadHandle); And everything is ok.
And what to do if it is implied that the flow should work all the time (along with the application) and its completion will be only at the completion of the entire application. Do I have to wait on the flow execution on FormClose? (for example, using mutex). Is it enough just to inform the flow that it will be closed by setting a certain flag?
I quote (Delphi Rei Lishner Handbook) "When a form closes it interrupts the flow. It is possible that the message on the completion of the flow (if the flow on exit, after analyzing the completion flag set by FormClose is PostMessage form) will come after the destruction of the form, but it will not big problem since Windows will destroy the thread when the program ends. " And if some objects will be created in my flow function, will they be correctly destroyed in this case ??? unclear? or if the code for such a plan ...
function ThreadFunc ();
was
T: TMyObject;
begin
T: = TMyObject.Create;
while (TRUE) do
begin
....
sleep (20000);
end;
T. Free;
PostMessage (Form1.Handle, WM_FINISHED, 0,0);
end;
Is the destruction guaranteed T ??? and whether such code will come to a possible application hangs on closing for a time before 20 seconds ???
Thank you!



MaxDDinc   (2004-10-31 00:12) [1]

Any program objects, including threads (processes), will be destroyed when the main window is closed. The delay in the thread will not cause the program to hang, since it is separate from the main thread, which is allocated its own quantum of time to solve its own problems



Pages: 1 whole branch

Forum: "WinAPI";
Current archive: 2004.12.12;
Download: [xml.tar.bz2];

Top









Memory: 0.56 MB
Time: 0.076 c
14-1101297881
Mage Pohmelyaynen
2004-11-24 15:04
2004.12.12
About girls and voltmod


8-1095352608
UserUserov
2004-09-16 20:36
2004.12.12
Console graphics in Delphi


3-1100619712
~ Blade ~
2004-11-16 18:41
2004.12.12
Update table in ado


1-1101856765
newage
2004-12-01 02:19
2004.12.12
derivative class your own


1-1101608757
Bobby digital
2004-11-28 05:25
2004.12.12
Listbox pt.2





afrikaans albanian Arabic armenian azerbaijani basque belarusian bulgarian catalan Chinese (Simplified) Chinese (Traditional) croatian Czech danish Dutch English estonian filipino finnish French
galician georgian German greek haitian Creole hebrew Hindi hungarian icelandic indonesian Irish italian Japanese Korean latvian lithuanian macedonian malay maltese norwegian
persian polish portuguese Romanian russian serbian slovak Slovenian Español swahili Swedish thai turkish Ukrainian urdu vietnamese welsh yiddish bengali bosnian
cebuano Esperanto gujarati hausa hmong igbo javanese kannada khmer lao latin maori marathi mongolian nepali punjabi somali tamil telugu yoruba
zulu
English French German Italian Portuguese Russian Spanish