5
votes

I have a thread, called TAlertThread. The thread interacts with its owner by triggering events. For example, when certain data is available inside the thread, it sets some temp variables and calls Synchronize(UpdateAlert) which in turn triggers the appropriate event.

Now the thread works perfectly in any standard windows application. My problem is when I put that thread inside of an ActiveX form (TActiveForm). The ActiveX control (aka COM object) is then embedded inside of a Windows Desktop Gadget (via HTML / Javascript). I also have experience with this, the gadget is not the issue. The ActiveX component works fine in its destination, except the thread is never executed. It's even being called EXACTLY the same way as I called it from the App.

Is this some limitation with ActiveX, blocking threads from executing? I wouldn't think so, because other things that require threads internally (such as TADOConnection) work. I am in fact properly calling CoInitialize and CoUninitialize appropriately. Again, works perfect in an application, but does not work at all in ActiveX.

Here is how I call this thread...

procedure TRMPDashXS.ExecThread;
begin
  //Thread created suspended
  lblStatus.Caption:= 'Executing Thread...'; 
  fThread:= TAlertThread.Create(fConnStr); //fConnStr = connection string
  fThread.Priority:=      tpIdle;
  fThread.OnConnect:=     Self.ThreadConnected;
  fThread.OnDisconnect:=  Self.ThreadDisconnected;
  fThread.OnBegin:=       Self.ThreadStarted;
  fThread.OnFinish:=      Self.ThreadFinished;
  fThread.OnAlert:=       Self.ThreadAlert;
  fThread.OnAmount:=      Self.ThreadAmount;
  fThread.Resume; //Execute the thread
end;
2
To clarify, I mean "Not working" as in the Execute procedure is never called by the thread. - Jerry Dodge
Umm.. missing 'override' on execute method declaration? Just a guess - I've never seen anything like this happen. My threads always reach the first line of the execute method before blowing up. - Martin James
Oh - 'tpIdle'. Try raising that to tpNormal, just for now.. - Martin James
Synchronize requires co-operation from the host app. I can't see that a Windows desktop gadget is going to help you there. Try sending a message instead. - David Heffernan
Look at the implementation of Synchronize. It places the method to be executed on the main thread into a list and then waits until it has been processed. Meanwhile, the main thread needs to know of the existence of this list, check it, process any methods, and signal their completion. This is what I mean by cooperation. You need you main thread to partake in this process and I bet it is not doing so. I don't know enough about ActiveX to be confident about this or even to suggest a solution. - David Heffernan

2 Answers

7
votes

I suspect this might describe exactly what you're experiencing in your version of Delphi:

I'm not sure if that helps ... but I hope it does. At least a little :)

PS: Is there any particular reason you have to use Com/ActiveX and/or TActiveForm?

0
votes

According to this article here: http://edn.embarcadero.com/article/32756 web browsers don't allow threading via ActiveX. However that still doesn't explain why it doesn't work when I put it in a C# application.