?
Solved

Problem with accessing form controls in response to handling COM object events

Posted on 2006-10-26
6
Medium Priority
?
196 Views
Last Modified: 2010-04-30
Hi all,

I am a newcomer to VB 2005, and have a project working that handles events from a COM object. Strangely, simple things -like displaying a message box inside the event handling subroutine, or changing the text of an edit control- work, but others, like starting a timer or updating a progress bar inside a status strip won't. In the code below, the attempt to set the progess bar to 50 in response to eventcode 1 does nothing and generates "A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll". The DelayedAction timer in response to eventcode 0 will not execute, or -strangely- only the second time it is started??? I have checked that these will work if called from inside the form1_load sub or anywhere else as long as the event handler is not "involved".

Friend Class Form1
Public WithEvents Camera As MaxIm.CCDCamera

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Camera = CreateObject("Maxim.CCDCamera")
Camera.LinkEnabled = True
Camera.EventMask = (-1)
Exposure_ProgressBar.Value = 0
Exposure_ProgressBar.Maximum = 100
End Sub

Private Sub Process_CameraEvent(ByVal CameraEventCode As Short)
Select Case CameraEventCode
Case 0
DelayedAction.Start()
Case 1
Exposure_ProgressBar.Value = 50
Case 8
Case 14
MsgBox("Connected")
Sequence_StatusText.Text = "Connected"
Case 15
MsgBox("Disconnected")
End Select
End Sub

Private Sub Camera_Notify(ByVal EventCode As Short) Handles Camera.Notify
Process_CameraEvent(EventCode)
End Sub

Private Sub DelayedAction_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DelayedAction.Tick
MsgBox("Delayed Action")
DelayedAction.Stop()
End Sub

End Class


Frankly, I don't know what to do next. But something must be wrong in how I've set this up. Thanks in advance for any hints!

Robert
0
Comment
Question by:schling
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17815633
Do you know if the MaxIm.CCDCamera is using Threads?
0
 

Author Comment

by:schling
ID: 17815686
No, unfortunately I don't. But could ask their user support.
0
 

Author Comment

by:schling
ID: 18032517
I did find the answer. The solution was to make  "thread-safe" calls via invoke and a delegate function.
Since the question whether Maxim uses threads lead me to investigate invoke, I'd agree to split points.

Robert
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18118984
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question