Threading -

G

Guest

Hi everyone,

I would appreciate any help concerning this threading issue.
I am using the comm port, and receiving data from the comm port fine.
I am updating the system.form controls, text boxes, using "begininvoke" and
the updates occur, no problem.
However after the update,, the form is about as responsive as a herd of
turtles running through peanut butter. What am I missing?
Here is the code:

GENERAL:
Public Class Form1
Inherits System.Windows.Forms.Form
Private Shared m_FormDefInstance As Form1
....
etc.

-------------------------------------------
Form1 Load event:
m_FormDefInstance = Me
etc.
------------------------------------------

Comm port:----------------------------
Private Sub m_CommPort_DataReceived(ByVal sender As Object, _
ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles
m_CommPort.DataReceived

Dim strModemRecBuffer As String = ""
strModemRecBuffer = m_CommPort.ReadExisting
'Update MAINFORM Controls
m_FormDefInstance.BeginInvoke(New _
DisplayData(AddressOf ProcessCallerData), _
New Object() {strModemRecBuffer})
End Sub
------------------------------------------------------------

Public Delegate Sub DisplayData(ByVal strCallerIdDataBuffer As String)

Private Sub ProcessCallerData(ByVal strCallerIdDataBuffer As String)
'Update the text box with caller-id (Works fine)
' I do some formatting for the <Cr> in the caller-id fields, but
'that is all working fine
text1.text = strCallerIdDataBuffer
text1.refresh
end sub

The caller-id data comes out fine, and then the form goes to slug mode.
Any help would be appreciated, thank-you in advance
Am I missing something with the thread?
 
D

Dmytro Lapshyn [MVP]

Hi Leo,

Blind guess - try removing the "text.refresh" line from the
ProcessCallerData subroutine.
 
G

Guest

Hi Dmytro,

I tried your suggestion, and same problem.
But you got me thinking about the "properties" of the textbox.

I don't understand why, but when I changed the property of the textbox to
"Readonly=TRUE" from the IDE and then in the program
(After the DataReceivedEventFires) And In The Sub (ProcessCallerId)
(1) Change it to false
(2) Update it for the Caller-Id
(3) Set it back to ReadOnly =TRUE
Then it seems, (I say seems because I want to test and test before I call it
done)
Then the program is responsive (ie,all functions of program work fine so
far...)

Any ideas why this would (Seem) to eliminate the problem?
Could it be doing something in the thread with the property set to TRUE.

Leo
 
D

Dmytro Lapshyn [MVP]

Hmmm.. that's really weird... a textbox being R/O or not, this has
absolutely nothing to do with threading.
Here's another suggestion - replace BeginInvoke with Invoke. Updating the
textbox' contents should be quick, so I think it is OK if the worker thread
stops and waits while the textbox' value is updated.

If the problem persists, try a profiler (I recall there was a freeware one).
 
G

Guest

Here's another suggestion - replace BeginInvoke with Invoke. Updating the
textbox' contents should be quick, so I think it is OK if the worker thread
stops and waits while the textbox' value is updated.

I'll try this thanks for the suggestion.

A little further update, I have been testing it today, and...

1. If I DO NOT click inside the text box (Any of the textboxes that I have
updated in the second thread, using the begin.invoke the program works ok, so
far)

2. If I click in ANY of the textboxes (That were updated in the thread),
then the program goes un-responsive.

I'll try your suggestion and let you know.
Thanks, Leo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top