开发者

mscomm oncomm event

开发者 https://www.devze.com 2023-02-16 12:10 出处:网络
I am in support of an application 开发者_如何学Pythonthat involves serial port communication. There are 32 MSComm controls (control array) on the form.

I am in support of an application 开发者_如何学Pythonthat involves serial port communication.

There are 32 MSComm controls (control array) on the form.

Suppose data arrived at one of the com port while some other code of the same thread is running (say database access etc.). will the Oncomm event procedure queed for execution or the current execution point is queed and Oncomm event handler is executed?


VB6 is single threaded. Basically (excepting ActiveX controls for a second) there's just the GUI thread.

It's sitting there waiting for an event. You get data, so it enters the event handler for your MSComm control and starts doing some database access. It blocks waiting for the database to respond. Another MSComm control receives data and fires off an event. This event just sits in the Windows event queue. The GUI thread has to exit the event handler before it can process the other MSComm event.

Of course, in the middle of an event handler you can call DoEvents. I highly suggest you rarely, if ever, do that. It's the source of many difficult bugs, in my experience.

There are ways to queue the long running database work onto a background thread (using a call into .NET managed code, in that case). That will allow your event handler code to continue almost immediately without blocking, allowing it to process the next message. To my knowledge, there's no native VB6 way to do that.

0

精彩评论

暂无评论...
验证码 换一张
取 消