Skip to main content
4-Participant
January 6, 2023
Solved

Adding VirtualThing after threadpool is started

  • January 6, 2023
  • 1 reply
  • 2211 views

Hi,

 

I am creating an application with the .net sdk that will run virtual things in a process. But I would also like to connect some virtual thing at any moment in the process.

 

Example: I start my application with thing1 and thing2. Then a few hours later I want to add thing3.

 

How would I be able to do so? Is it possible?

 

Regards, 

 

François Lévesque

Best answer by nmutter

I think the question is related to the creation of a new instance - in context of the SteamSensor Example - of a new SteamThing in the already running application.

https://support.ptc.com/help/thingworx/edge_sdk_dotnet/en/#page/dotnet_sdk/c_dotnet_sdk_reference_virtualthing_class.html#wwID0E3BIM

SteamSensorClient client = createClient(host, appKey);

/* (done in createClient call)
	// Create two Virtual Things 
	SteamThing sensor1 = new SteamThing("SteamSensor1", "1st Floor Steam Sensor", null, client);
	SteamThing sensor2 = new SteamThing("SteamSensor2", "2nd Floor Steam Sensor", "SN0002", client);

	// Bind the Virtual Things
	client.bindThing(sensor1);
	client.bindThing(sensor2);
*/

// Wait for the SteamSensorClient to connect, then process its associated things.
// As long as the client has not been shutdown, continue
while (!client.isShutdown())
{
	// Only process the Virtual Things if the client is connected
	if (client.isConnected())
	{
		ThreadPool.QueueUserWorkItem(client.runClient);
	}
	
	// Question: Can we here also create new SteamThings and bind it to the client?
	
	// Suspend processing at the scan rate interval
	Thread.Sleep(scanRate);
}

 

I did not yet do it like this. I cannot answer this question.

 

1 reply

22-Sapphire I
January 9, 2023

You have a full set of services available that you could invoke after connection. So it is certainly possible to do things like auto create based on a trigger, or 'self-registration' there have been several threads on this, quite a long time ago, hopefully you can find it using a search.

4-Participant
January 9, 2023

I've been searching all day for a post that would give me what I am looking for and I found nothing. Would it be possible to point me in the right direction please. Since I am new to the sdk and ThingWorx.

 

Regards

nmutter16-PearlAnswer
16-Pearl
January 12, 2023

I think the question is related to the creation of a new instance - in context of the SteamSensor Example - of a new SteamThing in the already running application.

https://support.ptc.com/help/thingworx/edge_sdk_dotnet/en/#page/dotnet_sdk/c_dotnet_sdk_reference_virtualthing_class.html#wwID0E3BIM

SteamSensorClient client = createClient(host, appKey);

/* (done in createClient call)
	// Create two Virtual Things 
	SteamThing sensor1 = new SteamThing("SteamSensor1", "1st Floor Steam Sensor", null, client);
	SteamThing sensor2 = new SteamThing("SteamSensor2", "2nd Floor Steam Sensor", "SN0002", client);

	// Bind the Virtual Things
	client.bindThing(sensor1);
	client.bindThing(sensor2);
*/

// Wait for the SteamSensorClient to connect, then process its associated things.
// As long as the client has not been shutdown, continue
while (!client.isShutdown())
{
	// Only process the Virtual Things if the client is connected
	if (client.isConnected())
	{
		ThreadPool.QueueUserWorkItem(client.runClient);
	}
	
	// Question: Can we here also create new SteamThings and bind it to the client?
	
	// Suspend processing at the scan rate interval
	Thread.Sleep(scanRate);
}

 

I did not yet do it like this. I cannot answer this question.