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.54 MB
Time: 0.049 c
1-1101882072
VAV
2004-12-01 09:21
2004.12.12
Downloading data and Ineta


1-1101638291
AdmeraL.
2004-11-28 13:38
2004.12.12
Form


14-1101138906
Dok_3D
2004-11-22 18:55
2004.12.12
Elections..


1-1101728709
Bobby digital
2004-11-29 14:45
2004.12.12
Combo


3-1100521367
VadimK
2004-11-15 15:22
2004.12.12
Creating Cursor in CP through dbExpress components





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 Spanish 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