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 846931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:41:51+00:00 2026-05-15T06:41:51+00:00

we’re developing a software to control a scientific measuring device. it provides a COM-Interface

  • 0

we’re developing a software to control a scientific measuring device. it provides a COM-Interface defines several functions to set measurement parameters and fires an event when it measured data.

in order to test our software, I’m implementing a simulation of that device.

the com-object runs a loop which periodically fires the event. another loop in the client app should now setup up the com-simulator using the given functions.

I created a class for measuring parameters which will be instantiated when setting up a new measurement.

// COM-Object
public class MeasurementParams
{
    public double Param1;
    public double Param2;
}

public class COM_Sim : ICOMDevice
{
    public MeasurementParams newMeasurement;
    IClient client;

    public int NewMeasurement()
    {
        newMeasurment = new MeasurementParam();
    }

    public int SetParam1(double val)
    {
        // why is newMeasurement null when method is called from client loop
        newMeasurement.Param1 = val;
    }

    void loop()
    {
        while(true)
        {
            // fire event
            client.HandleEvent;
        }
    }
}

public class Client : IClient
{
    ICOMDevice server;

    public int HandleEvent()
    {
        // handle this event
        server.NewMeasurement();
        server.SetParam1(0.0);
    }

    void loop()
    {
        while(true)
        {
            // do some stuff...
            server.NewMeasurement();
            server.SetParam1(0.0);
        }
    }
}

both of the loops run in independent threads. when server.NewMeasurement() is called, the object on the server is set to a new instance. but in the next function, the object is null again. do the same when handling the server-event, it works perfectly, because the method runs in the servers thread. how to make it work from client-thread as well.

As the client is meant to be working with the real device, I cannot modify the interfaces given by the manufacturer. also I need to setup measurements independent from the event-handler, which will be fired not regularly.

I assume this problem related to multithreaded-COM behavior but I found nothing on this topic.

  • 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-05-15T06:41:51+00:00Added an answer on May 15, 2026 at 6:41 am

    What is the threading model of the client and the server – STA or MTA? (For reference – STA are single-threaded Com objects meant to allow access to their public methods from only one thread at a time and MTA are multi-threaded objects that allow concurent access to their public methods from multiple threads)

    How many instances do you have of each of them and how do you create these? I suspect you want only one, but you are ending up with multiple instead.

    How many threads do you have and which method is running on which thread? How do you create those threads and are they initialized to run STA objects or MTA?

    Note: .NET is smart enough to detect if both the client and the server are managed and will take COM out of the picture. So, your simulation is running pure managed code. If you want proper test client, you need to write it as a C++ (as I suspect your device controller is unmanaged code).

    Reference documentation about COM threading models:

    Understanding and Using COM Threading Models
    Processes, Threads and Appartments
    Introduction to COM Interop

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.