Re: ThreadStart parameters



"Mike P" <mike.parr@xxxxxxxxx> wrote in message news:%23C166Q6aHHA.4832@xxxxxxxxxxxxxxxxxxxxxxx
I can't find any online examples that actually show the syntax required
for passing parameters to ParameterizedThreadStart. Here is my code
that I have tried that doesn't work :

System.Threading.ThreadStart thdStart = new
System.Threading.ParameterizedThreadStart((MoveMail), new object[] {
progress, oItems, destfolder, objConn });
System.Threading.Thread thd1 = new
System.Threading.Thread(thdStart);
thd1.Start();

The ParameterizedThreadStart constructor only takes the delegate to the start procedure. The parameter itself is passed on the Start method:

System.Threading.ParameterizedThreadStart thdStart = new System.Threading.ParameterizedThreadStart(this.MoveMail);
System.Threading.Thread thd1 = new System.Threading.Thread(thdStart);
thd1.Start(new object[] {progress, oItems, destfolder, objConn });

Notice that you can only pass a SINGLE parameter of type object. You can put anyting inside an object, in this case an array of objects that contains four elements. Be sure to adjust your MailMove method accordingly (it should take only one object, not four, and then extract those four objects from inside the one that you passed).

.