Solved

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

Posted on 2006-10-26
6
190 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
  • 2
6 Comments
 
LVL 85

Expert Comment

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

Author Comment

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

Author Comment

by:schling
Comment Utility
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
Comment Utility
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now