serial_on_com error

Put Claude

Active Member
Licensed User
Longtime User
hi,

Still trying to Opti-Compile my GPS apps in net2...
Loaded the error message extention file so I can read the errors.
It tells me to change baudrate (used 115200, maximum accepted is 65xxx)
Did so and get the next error...
get the error on serial_on_com sub as: "Control.Invoke must be used to interact with controls created on a separate thread."
disabled this line in sub serial_on_com :
If F1IBconnect.Visible=TRUE Then F1IBconnect.Visible=FALSE
and the error for serial_on_com sub disapear, but now two other subs have the same control.invoke error.

What does it means, what do I have to do ???

Put Claude Belgium
 
Last edited:

agraham

Expert
Licensed User
Longtime User
What does it means, what do I have to do ???
I assume that the subs in which this error occurs are event subs. It is a limitation of .NET that operations on controls are not "thread safe" so only the thread that creates the controls can safely manipulate them. A thread is an unit of executing code within a process. B4PPC is a process and usually only consists of a single thread that creates the controls and does all the manipulation.

Operations in B4PPC libraries and B4PPC itself are usually "synchronous" which means that the one thread B4PPC is running on waits for things to happen or time out. It looks like the serial library does some things "asynchronously" which means that a new thread of execution is started to wait for something to happen and the original thread carries on. These asynchronous threads then call a B4PPC event sub when required.

This is an interesting by-product of the optimising compiler, I wonder if Erel foresaw this? I think the original compiler dealt with events by putting an event message on the main B4PPC thread message queue where it is safe to manipulate controls. It looks like the optimising compiler executes them directly where it is not safe to manipulate controls if they are called on a different thread.

I can see this causing you (and I!) difficulty. There is a way round this in the full .NET Framework called Control.Invoke but you can't do it in B4PPC. You need to get an indication back to your main B4PPC code that something has happened. It may be that you have to set a global flag and monitor it in a timer loop which does run on the main thread. Erel may need to have a think about this!
 
Last edited:

Put Claude

Active Member
Licensed User
Longtime User
Hi agraham,

I understand the red wire in your explanation, I am in the serial thread from where I will do something in my B4PPC app., and that is something that needs special manipulation...
In fact I was already searching for that Control.Invoke matter, but did not find it...
So I think there is not a simple workaround for this, and I have to stay in Net1
Thanks a lot fore your time to write this.

Put Claude Belgium
 

Put Claude

Active Member
Licensed User
Longtime User
Hi Erel,

I put the files, compile my GPS app. where I use the OnComEvent... and yes...yes...yes, it's working like hell.
So... working now in version 6 in NET2 and opti-compile, if in some time we can work pixeldoubbling for the VGA-screens, it is almost the perfect fast developers thing. Think agraham will be pleased to.

Thanks again Erel

Put Claude Belgium
 
Last edited:
Top