Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.5 Threading threads
Hi experts, i wanna ask u about multithread with some parameters. I've a problem when i want to send some parameters. Frown | :(
 
I have three methods and three parameters in each other :
 
private void SendAckDetail(string memberID, string partName, string AccNum)
{
  //-- process
}
 
private void InsertToDB(string bankCode, string partName, string AccNum)
{
  //-- process
}
 
private void CreateXMLData(int totalRec, string ExtRef, string Curcod)
{
  //-- process
}
 
I've tried this methode to handle multithread with some parameters but it hasn't worked properly... Confused | :confused:
 
oThread1 = new Thread(delegate() { SendAckDetail(memberID, partName, AccNum); });
oThread2 = new Thread(delegate() { InsertToDB(bankCode, partName, AccNum); });
oThread3 = new Thread(delegate() { CreateXMLData(totalRec, ExtRef, Curcod); });
 
oThread1.Start();
oThread2.Start();
oThread3.Start();
 
Would u help me please experts ??... Confused | :confused: Confused | :confused:
Posted 15-Aug-10 18:55pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can try like following.
 
class Program
    {
        static void Main(string[] args)
        {
            ThreadTest t = new ThreadTest();
            Acknowledgement acknowledgement= new Acknowledgement();
            acknowledgement.AccNum = "123";
            acknowledgement.MemberID = "M123";
            acknowledgement.PartName = "P23432";
            Thread oThread1 = new Thread(t.SendAckDetail);
            oThread1.Start(acknowledgement);
        }
 
       
    }
    struct Acknowledgement
    {
        public string MemberID { get;  set; }
        public string PartName { get; set; }
        public string   AccNum { get; set; }
 
        
    }
    class ThreadTest
    {
 

        public void SendAckDetail(object ack)
        {
         Console.WriteLine(((Acknowledgement)ack).MemberID);
         Console.WriteLine(((Acknowledgement)ack).PartName);
         Console.WriteLine(((Acknowledgement)ack).AccNum);
        }
        
    }
 
Similarly you can do this for other methods also.
  Permalink  
v4
Comments
Teamsar at 16-Aug-10 1:17am
   
ParameterizedThreadStart has a method void(obj). If i use this code :
oThread1 = new Thread (new ParameterizedThreadStart(SendAckDetail));
oThread1.Start(memberID,partName,AccNum);
There are many errors occur.. :(
Prakash Kalakoti at 16-Aug-10 2:00am
   
I have updated the answer, you can do like as mentioned in the answer.
Teamsar at 16-Aug-10 3:25am
   
Reason for my vote of 5
This code is helpful for me.
Teamsar at 16-Aug-10 3:26am
   
Thank you Prakash Kalakoti :), this code is very helpful for me.. :)

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

  Print Answers RSS
0 OriginalGriff 406
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 205
3 Raul Iloc 170
4 Maciej Los 164
0 OriginalGriff 8,289
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,624
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 16 Aug 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100