raidos
asked on
Thread question...
I'm currently recoding an old app, because it was too ugly for me..=)
Now i am unsure if where events would fire....
If i create a tthread descendant like this...
Type
TMyThread = Class(TThread)
Private
fMyComp : TMyComponent;
Protected
Procedure Execute;
Public
Procedure SomeSillyEvent(Sender: TObject);
Constructor Create;
Destructor Destroy;
End;
Constructor Create
Begin
Inherited Create(True);
CreateMyComponent; //P-Code, it just does it.
fMyComp.MyTriggerEvent := SomeSillyEvent;
Suspended := FALSE;
End;
Procedure Execute;
Begin
While Not Terminated do
Sleep(5);
End;
Where would the trigger event run ?
Inside the thread or inside the thread that called the TMyThread.Create; ?
Hoping for a speedy response.. =)
Regards
//raidos
Now i am unsure if where events would fire....
If i create a tthread descendant like this...
Type
TMyThread = Class(TThread)
Private
fMyComp : TMyComponent;
Protected
Procedure Execute;
Public
Procedure SomeSillyEvent(Sender: TObject);
Constructor Create;
Destructor Destroy;
End;
Constructor Create
Begin
Inherited Create(True);
CreateMyComponent; //P-Code, it just does it.
fMyComp.MyTriggerEvent := SomeSillyEvent;
Suspended := FALSE;
End;
Procedure Execute;
Begin
While Not Terminated do
Sleep(5);
End;
Where would the trigger event run ?
Inside the thread or inside the thread that called the TMyThread.Create; ?
Hoping for a speedy response.. =)
Regards
//raidos
the event would run inside the original thread that created the object, the way it is coded now.
ASKER
That's what i figured...
If i move the CreateMyComponent into the Execute then..
will it fire inside the TMyThread then ?
If i move the CreateMyComponent into the Execute then..
will it fire inside the TMyThread then ?
Hmm, not so sure about swift's answer... Correct me if I am wrong, but I would say that the event code will be called in the main vcl thread, since I presume that the component is a vcl component, all which use the main thread. What are you looking to acheive? I may be able to offer a suggestion, or two...
ASKER
The component is a TApdComport, Turbo Power Async Pro, it is a nonvisual component.
Hope i can get some more input on this..
Regards
//raidos
Hope i can get some more input on this..
Regards
//raidos
Ok. Am I to take it that you are looking to process the received data in a thread? If so, then you could look into the possibility that the event handler actually stores the data to be processed by the thread and then signals it to do its work. Clearly, this depends on what you are looking to do. May I ask why you are looking to handle the event in a thread, rather than processing in the main thread? Clearly serial comms is quite a slow process, and the OS itself provides a degree of abstraction away from this and I would imagine that on a reasonable spec PC, the need for threaded processing of serially gathered data is not too high. If you want to tell me more about what you are looking to do, I may be able to help further - got a few years of Asynch pro experience under my belt :o)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks swift...looks similar to what I would have guessed, i'll post a new question for you with points.
mdspencer, the reason i want to move these things into a thread is simple...they don't need much processing power so there is no reason to have it hanging in the main thread should something go terribly wrong.
Also the application may contain 4 concurrent comport each doing something different than the other...
The application is a NT service, so i do not like having anything that even if not crash-prone, must never stop the main thread, if some error occurs within the thread...i can just free it and restart it.
Anyway...it is somewhat important...
mdspencer, the reason i want to move these things into a thread is simple...they don't need much processing power so there is no reason to have it hanging in the main thread should something go terribly wrong.
Also the application may contain 4 concurrent comport each doing something different than the other...
The application is a NT service, so i do not like having anything that even if not crash-prone, must never stop the main thread, if some error occurs within the thread...i can just free it and restart it.
Anyway...it is somewhat important...
raidos:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
Hi!
No comment has been added lately and this question is therefore classified abandoned.
If asker wishes to close the question, then refer to
https://www.experts-exchange.com/help/closing.jsp
Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: swift99
Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
...Snehanshu
EE Cleanup Volunteer
No comment has been added lately and this question is therefore classified abandoned.
If asker wishes to close the question, then refer to
https://www.experts-exchange.com/help/closing.jsp
Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: swift99
Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
...Snehanshu
EE Cleanup Volunteer