🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #17730

OnPaint with Semaphore seems not working...

#17730
From: Phuoc Can HUA
Date: Tue, 04 Mar 2003 00:26
25 lines
2137 bytes
I've posted a problem with Canvas->CopyRect sometime ago. It seems I found
the reason of that problem. But still can't solve it  :-(

In my program, I'm using a WorkSpace (Bitmap) to apply all the graphic
operations (e.g. CopyRect). Then I use CopyRect to copy the updated area
from WorkSpace to a PaintBox (visible Bitmap). At the same time, I'm using a
OnPaint procedure which is copying the entire WorkSpace into PaintBox.
Everything seems OK when I was using TTimer to draw my WorkSpace.

Now I changed my program to use TThread to draw on the WorkSpace.
Unfortunately, it could happen that while the thread is drawing the OnPaint
procedure is called, i.e. the PaintBox is restored with an unfinished image.

Now I'm trying to use Semaphore (max value= 1) to fix it. I use
WaitForSingleObject() and ReleaseSemaphore() to enclose the codes of
modifying the WorkSpace and also enclose the OnPaint codes. I hope if
OnPaint is called and WorkSpace is busy OnPaint will wait until WorkSpace
Semaphore is released. But it seems there's no effect at all :-(

What did I do wrong? I also read something about EnterCriticalSection(), I
thought I don't need it because I'm usig only one flag, do I need it?
Any better solution?

Thanks
Phuoc Can HUA
Technical Details
Message-ID: <3e63f403$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,7b93bd55840acb0
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-03-04 12:33:29 PST
From: "Phuoc Can HUA" <home+a+t+huaonline.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: OnPaint with Semaphore seems not working...
Date: Tue, 4 Mar 2003 11:26:40 +1100
Lines: 28
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2720.3000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 210.9.89.210
Message-ID: <3e63f403$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1046737923 210.9.89.210 (3 Mar 2003 16:32:03 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail