[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

TBitmap from a thread

Posted on 2004-04-01
5
Medium Priority
?
208 Views
Last Modified: 2010-04-04
I have a component that is a descendant of a TImage. I use this to play back a custom video format I created.

I have created a thread for my playback loop (both to wait for data over the network before continuing, and for timing). This loop pauses as long as it needs to and then enters a critical section to call a procedure that processes the data and draws it to the canvas.

If I create that loop in the main thread, I don't run into any problems. However when I move that loop the a thread, it will work for a few seconds and then stop drawing. Everythign acts as though it is still working except the data is never displayed.

The loop will be the only thing that calls anything that draws. I tried TCanvas.Lock/Unlock however it just freezes.

Any tips on what to look for?

0
Comment
Question by:rbohac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 26

Expert Comment

by:Russell Libby
ID: 10733017

Are you synchronizing the actual data processing/drawing with the main thread? Attempting to interact with the main thread (where the component lives), can cause thread deadlocking and all sorts of other bizarre results.

Regards,
Russell
0
 
LVL 6

Author Comment

by:rbohac
ID: 10733050
I thought I was by entering a critical section first....
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 1000 total points
ID: 10733101

A CS enter/leave is good for handling a section of code that should only have one thread in it at a time. But when dealing with components, the component may be accessed by the other thread outside of your section of code. Say for example, a WM_PAINT, or other message gets processed that affects the component. Then both threads are attempting to manipulate the component. Not good...

So no, a CS is not going to cut it when dealing with components (the whole VCL is not thread safe). I would suggest that the actual component loading and image drawing should be done in a synchorinzed method which would then run in the main thread, which is where the component lives.

Regards,
Russell


0
 
LVL 6

Author Comment

by:rbohac
ID: 10733326
Figures it would be something like that. That was the problem. I thought a critical section did the same thing that synchronize did?
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 10734252

No, a CS is good for limiting access to a resource (be it a variable, non-vcl object, ect), just as long as all access is done in the CS protected block. With a vcl component, access cannot be protected that way, because the main thread is still pumping the message queue, and may process a message that performs some logic on the resource (component) that you are trying to protect. The only way around it is to perform the logic in the main thread.

Russell


0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question