Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to run Windows Console Application (C#/VB.NET) simultaneously or independently? I have a create a program that has its job to consume data from WSDL and pass to cloud for next processing. Code is run well on getting all devices but it have delay before complete get and send all devices on loop because there is about 170 ++ devices that need to be read.

Rather than having it delay too long before next cycle, how to automate running each device console separately? Do I need to create 170 ++ projects to achieve this? And will it be problem on running all of this console at the same time/some delay a bit?

What I have tried:

Create around 20 same projects and set multiple startup projects. Need another advice
Posted
Updated 27-Sep-16 4:50am
Comments
[no name] 27-Sep-16 10:39am    
Isn't this the same vague "question" you have been reposting over and over? Why would you even consider creating 170 different projects that do the same thing? Why don't you create one project that uses multiple threads to perform the work?
Philippe Mori 27-Sep-16 12:33pm    
Obviously, you are trying the wrong approach... bit it might be a good idea to first learn multithreading and then write code once you understand how it works. Otherwise, you might have a lot of bugs and instable application.

1 solution

Im not terribly clear on what you are trying to accomplish. I think what you are asking is what is the best way to do the same operation to 170 different devices.

You should look at threading/Tasks in .net.

C#
var tasks = new list<task>();
var deviceEndpoints = new List<string>();

foreach (var hostname in deviceEndpoints)
{
	var dhostname = hostname;
    tasks.add(task.factory.startnew(() =>
    {
		//based on the hostname, do something here with dhostname to send/retrieve your data from this device.
    }));
}

// This is to wait for all tasks to complete before proceeding
task.waitall(tasks.toarray());


Using the above code I was able to take a process that took close to 30-40 minutes of sequential procesisng down to 2 minutes using the async code above.

You can read more about tasks and multi threading here:

C# - Multithreading[^]

c# multithreading - Google Search[^]

C# Tasks - Google Search[^]

Task Class (System.Threading.Tasks)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900