Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi experts, i wanna ask u about multithread with some parameters. I've a problem when i want to send some parameters. :(

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:

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:
Posted

1 solution

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.
 
Share this answer
 
v4
Comments
Teamsar Muliadi 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.. :(
PSK_ 16-Aug-10 2:00am    
I have updated the answer, you can do like as mentioned in the answer.
Teamsar Muliadi 16-Aug-10 3:25am    
Reason for my vote of 5
This code is helpful for me.
Teamsar Muliadi 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)



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