Running more than two Dtsx packages In parallel using the concept of threads in a C # console application

I have a console application that should run the full 17 Dtsx SSIS packages below.

[1] In the first thread, it must execute 3 packets simultaneously at the same time [2] In the second thread, it must execute 5 packets at once in parallel and so on ...

I heard about a concept called parallelism that is used for higher versions of the .NET Framework 4.0, etc. However, I'm not sure how to implement the same in Projcet.

I have some examples using streams, here is my code snippet.

Thread.Sleep(2000); Thread First = new Thread(new ThreadStart(FirstThread)); Thread Second = new Thread(new ThreadStart(SecondThread)); Thread Third = new Thread(new ThreadStart(ThirdThread)); First.Start(); Second.Start(); Third.Start(); static void FirstThread() { try { DTSXProcesser pkgProcess = new DTSXProcesser(); pkgProcess.ExecutePackage("Customers.csv"); pkgProcess.ExecutePackage("RouteInfo.csv"); pkgProcess.ExecutePackage("Items.csv"); } catch (Exception ex) { Logger.Log("Exception in Execution Of Package. Error : " + ex.ToString()); Thread.ResetAbort(); } } 

Please help ...

+4
source share
1 answer

With .NET 4:

Using Tasks:

 Task[] tasks = new Task[]{ Task.Factory.StartNew(FirstThread), Task.Factory.StartNew(SecondThread), Task.Factory.StartNew(ThirdThread) }; Task.WaitAll(tasks); 

or with parallel class

 Action[] actions = new Action[] { FirstThread, SecondThread, ThirdThread }; Parallel.ForEach(actions, action => action()); 

And for the logic inside your methods ( FirstThread ...) you can implement the same concept (if there is no problem for executing the ExecutePackage method several times in parallel for the same DTSXProcesser instance).

If you are wondering which one you are using, you can see this question , but they are almost equivalent.

With .NET 4.5 and C # 5, you can use async await keywords.

+1
source

Source: https://habr.com/ru/post/1484770/


All Articles