Solved

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

Posted on 2006-10-26
6
195 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

726 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