Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-10-26
6
Medium Priority
?
199 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

618 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