Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8725525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:03:36+00:00 2026-06-13T08:03:36+00:00

This is a WinForms C# application. The following two snippits show two different ways

  • 0

This is a WinForms C# application.
The following two snippits show two different ways of initializing an object. They are giving different results.

This works as expected:

public partial class Form1 : Form
{
  private CameraWrapper cam;
  public Form1()
  {
       cam = new CameraWrapper();
       InitializeComponent();           
  }

This does not work (details below):

public partial class Form1 : Form
{
  private CameraWrapper cam = new CameraWrapper();
  public Form1()
  {
       InitializeComponent();
  }

Inside CameraWrapper I am using a third-party SDK to communicate with a camera. I register with an event on the SDK which is called when results are available.

In case 1 (initialization inside constructor), everything works as expected and the event handler inside CameraWrapper gets called. In case 2, the event handler never gets called.

I thought that these two styles of object initialization were identical, but it seems not to be the case. Why?

Here is the entire CameraWrapper class. The event handler should get called after a call to Trigger.

class CameraWrapper
{
    private Cognex.DataMan.SDK.DataManSystem ds;
    public CameraWrapper()
    {
        ds = new DataManSystem();
        DataManConnectionParams connectionParams = new DataManConnectionParams("10.10.191.187");
        ds.Connect(connectionParams);

        ds.DmccResponseArrived += new DataManSystem.DmccResponseArrivedEventHandler(ds_DmccResponseArrived);
    }

    public void Trigger()
    {
        SendCommand("TRIGGER ON");
    }

    void ds_DmccResponseArrived(object sender, DmccResponseArrivedEventArgs e)
    {
        System.Console.Write("Num barcodes: ");
        System.Console.WriteLine(e.Data.Length.ToString());
    }

    void SendCommand(string command)
    {
        const string cmdHeader = "||>";
        ds.SendDmcc(cmdHeader + command);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:03:37+00:00Added an answer on June 13, 2026 at 8:03 am

    I thought that these two styles of object initialization were identical, but it seems not to be the case.

    Not quite.

    In the first case, the CameraWrapper constructor is called after the base class constructor for Form. In the second case, the CameraWrapper constructor is called, then the base class constructor, then the Form1 constructor body.

    It’s possible that something within the Form constructor affects the execution of the CameraWrapper constructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a C# WinForms application. On my computer the following works: DateTime.ParseExact(13/05/2012,
I'm tweaking a WinForms application. This application has a Form that contains a PropertyGrid
I have a WinForms application with a bunch of third party references. This makes
I'm trying to implement this pattern in my WinForms application (I don't like it,
I am using Segoe UI for my winforms application. On XP, this font doesn't
I have a WinForms application. I've populated my ComboBox with the following code: cboGridSize.Items.Clear();
I've got a winforms application that is set up in the following manner: 2
I have a problem with databinding in a winforms-application. In the following code i
I am using the following expression in a local report for a WinForms application,
I have written and tested a WinForms application and everything works fine on my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.