Tuesday

.net Threading:Passing parameters to the thread for ParameterizedThreadStart in C# (csharp / dot.net)


0.Create MultiThreadArgument class and add all parameters for thread starting 
public class MultiThreadArgument {
public MerchantBase merchant;
public TransactionCollection transactionCollection;
public string email;
}

1.Thread starter in main thread class (thread class):
private void ThreadStarter(MerchantBase m, TransactionCollection c,string email){
if (c.Count > 0) {
Thread th = new Thread(new ParameterizedThreadStart(ThreadWorker));
// create class parameters :
MultiThreadArgument ma = new MultiThreadArgument();
ma.merchant = m;
ma.transactionCollection = c;
ma.email = email;
th.IsBackground = true;
th.Start(ma);
}
}

2.Thread worker in main class:
private void ThreadWorker(Object o) {
MultiThreadArgument ma = (MultiThreadArgument)o;
DateTime st = DateTime.Now;
string mid = ma.merchant.ID.ToString();
Logger.prn("*** Processing started for merchant #", mid , "transactions - ", ma.transactionCollection.Count.ToString());
ma.merchant.ProcessRequest(ma.transactionCollection, this);
.....
}

more...

No comments:

here is powershell script on how to get list of files from changesets associated with one tfs task

$dllPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\...