3

I have a Delphi 6 Pro program with a TWebBrowser component that loads a web page that embeds a Cool Iris Wall. The Cool Iris wall is an SWF object which means that when running, the execution happens inside the Adobe Flash player, an ActiveX or similar object I believe. The problem I am having is that sometimes when the Wall is loading pictures/videos from the web, it takes a big hit on the CPU on the main UI thread. I know that TWebBrowser moves most of its operations on to a background thread to keep the main UI thread happy, but something the Adobe Flash Player is doing is happening on the main UI thread and its causing my program much grief. Is there a way to move the Adobe Flash Player on to a background thread?

[UPDATE - 12/7/2010] - After a marathon probing and debugging session it turns out that the problem had to do with the Cool Iris Wall's Flickr proxy. You can interface with the Wall in two main ways: 1) You pass them special Flickr api protocol URLs and let them talk to Flickr for you, for example "api://www.flickr.com/?search=puppy" loads the Wall with the results of a Flickr keyword search for puppy. The advantage to this approach is that they do all the work for you necessary to make the query to Flickr and build the Wall's contents. 2) You build an RSS media feed yourself containing the photo stream item data and feed it to the Wall.

I was using technique #1. The problem is with #1 is that when their servers have trouble building the Flickr feed for you (for whatever unknown reason), their host SWF puts a heavy load on the CPU interfering with the main UI thread's operation. I converted my entire code base to work directly with the Flickr API and create the feed myself using the second technique and the problem vanished.

-- roschler

Robert Oschler
  • 14,153
  • 18
  • 94
  • 227
  • 9
    I really don't like when people downvote but don't add a comment explaining why. – Andreas Rejbrand Dec 06 '10 at 17:21
  • I'm very interested in this subject as well, did you check adobe's developer documentation? there must be a way to do this... however I see that all major browser crash or freeze when your flash application is trying to load a lot of objects -- I would suspect this would have been fixed by now if there were any possible way, however I could be wrong... –  Dec 06 '10 at 20:43
  • If you haven't done so already, try using a profiler to better pinpoint the source location of your problem. – Lieven Keersmaekers Dec 06 '10 at 21:04
  • @Lieven: I don't think the profiler will show anything usefull in this case since the cpu time consumption happens inside the browser and/or Flash Player object. – Remko Dec 06 '10 at 21:53
  • Are you sure that CoolIris uses Flash? I thought it used its own plugin. (In fact, I"m absolutely 100% certain.) It's worth checking. You may be able to directly host the plugin using the Mozilla plugin interface, which would bypass the need for TWebBrowser, and from there you may even be able to do so in another thread. – David Dec 06 '10 at 23:15
  • @Remko, you are probably right. If OP persists, he could use Procdump from SysInternals, create (serveral) dumps when the process spikes and use WinDbg to look at *what* it's doing when it spikes. It might give a clue that leads to a solution or at least an understanding of the problem. – Lieven Keersmaekers Dec 07 '10 at 06:58
  • @Andreas - I didn't downvote. Also, how do you know when someone has? @Lieven - it turns out the problem is with Cool Iris's Flickr proxy (api://www.flickr.com/). Converted my code to access Flickr directly and create a media feed for the Cool Iris wall. @David M - They do have a plugin but I am positive they use Flash since my code finds the Macromedia window they instantiate via their SWF at runtime in the Window chain. – Robert Oschler Dec 07 '10 at 20:47
  • @Robert: Of course you didn't downvote -- one cannot downvote one's own question (nor can one upvote them). When you get 1000 rep (http://stackoverflow.com/privileges/view-vote-counts), you can see the number of votes (both up and down) on each question and answer. And I saw that someone had downvoted your question (right now this question of your's has one downvote and three upvotes, so it says "+2"). But the downvoter obviously didn't add a comment explaining why, so I "compensated" by voting +1 on your question (this one). – Andreas Rejbrand Dec 07 '10 at 21:31

1 Answers1

0

You have no control over how the webbrowser manages its threading. If you do not want the webbrowser interfering with the main thread, then don't run the webbrowser in the main thread to begin with.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • This is clearly the only way to go but it may be difficult to achieve since Windows really wants all UI elements in the same thread (almost always the thread which runs the main program) – David Heffernan Dec 06 '10 at 21:21
  • Windows is quite happy to let UI windows run in worker threads. All that is required is a message loop in the thread. It is the VCL that does not like UIs outside of the main thread, and that is mainly because some of the VCL's internals, like MakeObjectInstance() (which is used to make TWinControl.WndProc() operate) are not thread-safe. – Remy Lebeau Dec 08 '10 at 22:16