As this is a significant rework of the original Threading library I have posted it in a new thread. The significant difference is that this version will operate in the IDE as well as when optimised compiled! That's right - you can now test threaded applications in the IDE - desktop and device! It seems to work fine in the IDE although obviously performance is not as good as when optimised compiled. I think it is pretty stable, I haven't experienced any crashes so far in testing so I think it is ready for the wider world.
The provision for locking resources has changed significantly. The previous RunLocked methods have been removed as they were inefficient to implement under the IDE. Instead two "proper" locking objects that are thin wrappers over two of the .NET locking objects are provided.
Thanks Erel . I figured out that if the IDE code is re-entrant enough to cope with calling StartSub for Events and CallSub, which can occur in expressions, it was probably OK for Threading. Seems OK so far! It's a spin-off from trying to get a full Debug suite for the device IDE - specifically the Caller code.
EDIT: I really meant DoEvents not Events!
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
and for this lib too :-[ (I'm say about adding a dispose method)
__________________
I'll Kill you, I'll Crash you, I'll never be yours!
--------------------------------------------------
Qtek s110; o2 XDA Flame; Nokia E63 red;
ASUS Eee PC 901 (Windows XP sp3) + TouchScreen;
first of all, thanks again for your great contribution..!
After some time went by i'm working on my piece of code where i embedded your threading lib a long time ago.It works great so far,currently having an issue with the thread is getting hung / crashing sometimes, but this is not subject of my post - not yet.
I intend to add more functions to my code, thus i need to check if a thread is still running.From the help file i found, that thread.running would be the property i have to check for, but unfortunately i could not figure out how to get this done.Likely, i'm facing the old problem : i do not think as much .NET as much it would be needed for this..*lol*
Basically, from my logic it would need to be done as following:
MyThread = CreateThread("MySub")
StartThread(MyThread)
If Thread.Running(MyThread) then ...
This is only an example, i know that the correct syntax is actually different from this.It is more PureBasic style, which i am using often for the pc as well.
This is a simplified version of my code in B4P:
AppStart
...
Thread.Start ( mySub)
...
AnotherSub
...
End Sub
MySub
..
do something
end Sub
AnotherSub
...
is the thread MySub still running ?
thread.running does not work, apparently the sub does not know about a thread object
EndSub
So how do i tell the thread.running what thread i am talking about...? Is it possible to use that property from a sub that was not the originator of the thread at all..?
I touch my B4P code first time after a quite long time i used other languages, so i apologize in advance if i overlooked something pretty easy...;-)
Sorry...still not understood.Can you explain that more in detail..? How do i reference to a thread object i created in a different sub..? When did i a give name to my thread object...?
I got it to run the way i intended from the beginning:
if thread.running = true then
Initially i got an error message saying i had to create first this object.So i was in the belief the code is wrong, but apparently the property gives that error if the thread instance is not there (yet).
But, my intention was to test if the thread has terminated itself, which i'm waiting for before i gonna do something else.
1. how can i test if a thread is still existing ?
2. how can i differentiate between multiple threads ?
the thread.running has no reference to a particular thread, so could not address the thread i want.
The error behavior - btw - is a pain in the ass, because half of my code is code that tries to prevent uncaught .NET errors from happening.Usually one would expect a certain return value if an object does not exists, but in B4P it just throws an ugly .NET exception to the user.To be honest - i don't like that at all.
Edit: i found a "feature" in my code and just moved the Thread.New1(B4PObject(1)) into the app start section.Now the thread.running does not cause an error anymore.Maybe this solved another issue i was facing with the thread.
throws an ugly .NET exception to the user.To be honest - i don't like that at all.
I am afraid that is how .NET (and Java and to an extent C++) is designed to work. They throw execeptions instead of returning error codes. The intention is to better separate error handling code from normal path of execution code.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.