suspicious delay when changing textbox properties??

  • Thread starter Thread starter weg22
  • Start date Start date
W

weg22

Hi all,

I'm developing a Visual Basic 2005 application to communicate with an
I2C device. I recently decided to add an i2c status bar. The status
bar is just a textbox with the following properties:

When I2C communication active:
Public Sub i2c_active()
statusBar.Text = "Exchanging Data..."
statusBar.BackColor = Drawing.Color.Red
End Sub

When I2C communication is idle:
Public Sub i2c_idle()
statusBar.Text = "IDLE"
statusBar.BackColor = Drawing.Color.Lime
End Sub

Ideally, the above properties are changed before and after the
get_i2c_data function. For example:
i2c_active()
get_i2c_data()
i2c_idle()

The problem is that the textbox properties for i2c_active() don't
change until after the get_i2c_data() function finishes. For example,
if I execute
i2c_active()
get_i2c_data()
the textbox doesn't turn red and display "Executing Data..." until
after it has already retrieved the data from the i2c device. This is
completely pointless!

There is some sort of delay between when the i2c_active() function
executes and when I see the textbox properties change. To debug, I
tried just executing the i2c_active() function and the textbox
properties change instantaneously. I need to have the textbox
properties change instantaneously when the get_i2c_data() function is
included. I'm not sure how to get this working. Any suggestions
would be appreciated.

Thanks,
-weg22
 
Although the "active()" function modifies the properties of the text box, it
won't get repainted until the function has exited and windows pumps its
message queue. You could try using the Refresh () method to force a paint
immediately after active().
 
Hi all,

I'm developing a Visual Basic 2005 application to communicate with an
I2C device. I recently decided to add an i2c status bar. The status
bar is just a textbox with the following properties:

When I2C communication active:
Public Sub i2c_active()
statusBar.Text = "Exchanging Data..."
statusBar.BackColor = Drawing.Color.Red
End Sub

When I2C communication is idle:
Public Sub i2c_idle()
statusBar.Text = "IDLE"
statusBar.BackColor = Drawing.Color.Lime
End Sub

Ideally, the above properties are changed before and after the
get_i2c_data function. For example:
i2c_active()
get_i2c_data()
i2c_idle()

The problem is that the textbox properties for i2c_active() don't
change until after the get_i2c_data() function finishes. For example,
if I execute
i2c_active()
get_i2c_data()
the textbox doesn't turn red and display "Executing Data..." until
after it has already retrieved the data from the i2c device. This is
completely pointless!

There is some sort of delay between when the i2c_active() function
executes and when I see the textbox properties change. To debug, I
tried just executing the i2c_active() function and the textbox
properties change instantaneously. I need to have the textbox
properties change instantaneously when the get_i2c_data() function is
included. I'm not sure how to get this working. Any suggestions
would be appreciated.

More than likely, the i2c_data method is blocking the UI thread so it
cannot process messages. One quick solution would be to add
statusBar.Refresh() after you change the text and color.

If that doesn't work, you may wish to move the processing of the
i2c_data code to a separate thread.

Chris
 
Hi all,

I'm developing a Visual Basic 2005 application to communicate with an
I2C device. I recently decided to add an i2c status bar. The status
bar is just a textbox with the following properties:

When I2C communication active:
Public Sub i2c_active()
statusBar.Text = "Exchanging Data..."
statusBar.BackColor = Drawing.Color.Red
End Sub

When I2C communication is idle:
Public Sub i2c_idle()
statusBar.Text = "IDLE"
statusBar.BackColor = Drawing.Color.Lime
End Sub

Ideally, the above properties are changed before and after the
get_i2c_data function. For example:
i2c_active()
get_i2c_data()
i2c_idle()

The problem is that the textbox properties for i2c_active() don't
change until after the get_i2c_data() function finishes. For example,
if I execute
i2c_active()
get_i2c_data()
the textbox doesn't turn red and display "Executing Data..." until
after it has already retrieved the data from the i2c device. This is
completely pointless!

There is some sort of delay between when the i2c_active() function
executes and when I see the textbox properties change. To debug, I
tried just executing the i2c_active() function and the textbox
properties change instantaneously. I need to have the textbox
properties change instantaneously when the get_i2c_data() function is
included. I'm not sure how to get this working. Any suggestions
would be appreciated.

Thanks,
-weg22


Application.DoEvents() inserted between the calls should update the textbox
prior to entering the second subroutine (If we are talking the same
language - I get confused over variations:)
 
Back
Top