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

Down

Thread: Suspend / Resume & Synchronize Find similar branches


mitry   (2001-12-15 02:53) [0]

Dear colleagues, help please, I have not slept 3 nights already.
The problem is:
If you frequently suspend (Suspend) and start (Resume) the thread that calls Synchronize, then when you redraw the window, the program often hangs.
For example, if you run the following program and switch between it and Delphi, then the application below will be silent forever:

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, ComCtrls;

type

TMyThread = class (TThread)
private
procedure Update;
protected
procedure Execute; override;
end;

TMainForm = class (TForm)
Timer1: TTimer;
procedure FormCreate (Sender: TObject);
procedure FormClose (Sender: TObject; var Action: TCloseAction);
procedure Timer1Timer (Sender: TObject);
private
{Private declarations}
MyThread: TMyThread;
public
{Public declarations}
end;

was
MainForm: TMainForm;

implementation

{$ R * .dfm}

procedure TMyThread.Update;
begin
//
end;

procedure TMyThread.Execute;
begin
repeat
Sleep (100);
Synchronize (Update);
until terminated;
end;

procedure TMainForm.FormCreate (Sender: TObject);
begin
MyThread: = TMyThread.Create (false);
Timer1.Interval: = 1;
Timer1.Enabled: = true;
end;

procedure TMainForm.FormClose (Sender: TObject; var Action: TCloseAction);
begin
Timer1.Enabled: = false;
if MyThread.Suspended then MyThread.Resume;
MyThread.Terminate;
MyThread.WaitFor;
MyThread.Free;
end;

procedure TMainForm.Timer1Timer (Sender: TObject);
begin
if not MyThread. Suspended then MyThread. Suspend else My Thread. Resume;
end;

All this is needed for this: I made an animated button: you point at it with the mouse - the stream starts playing, plays the animation, you remove the mouse - the flow stops. The user can carry the mouse quite often, so this leads to the above problem.
My program cannot use Timer instead of streams.
If someone tells you what's the matter, I will give him my best components (including an animated button). I solemnly swear.
I apologize for the long question, but in short it can not be.
Delphi6, Win98.
Thank you.



paul_shmakov   (2001-12-16 02:06) [1]

using suspend / resume is not the best solution in this case. And the use of the flow for each button is also bad. but once you need a stream, then why not make it easier: when the need arises to start playing the animation, we set the flag, the execute method checks this flag, and if it is set, it draws the animation. when the cursor is gone, we reset this flag.
the only thing that there were no problems, the flag should be changed by calling one of the Interlocked * functions. for example, InterlockedIncrement / InterlockedDecrement.

"I apologize for the long question, but in no way can it be."
all questions would be so long and detailed :)



Pages: 1 whole branch

Forum: "Main";
Current archive: 2002.01.08;
Download: [xml.tar.bz2];

Top









Memory: 0.82 MB
Time: 0.029 c
6-22316
dmur
2001-09-24 20:58
2002.01.08
Interception of errors when connecting using sockets


7-22451
Dmitri
2001-09-23 12:36
2002.01.08
Directive {$ I}


14-22325
Olgerd
2001-11-04 19:05
2002.01.08
Distribution


1-22051
kay
2001-12-18 22:22
2002.01.08
Richedit


3-21952
S_King
2001-12-04 10:18
2002.01.08
Determine the first free ID





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