Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 1.55 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Parameter count mismatch when trying to update across threads
  2. namespace ETL
  3.  {
  4.    public partial class Form1 : Form
  5.    {
  6.        private Thread myThread;
  7.        public delegate void delegatePrintoutProcess(string myString);
  8.        public delegatePrintoutProcess myDelegate2;
  9.   ...
  10.  
  11.     private void startParseToolStripMenuItem_Click(object sender, EventArgs e)
  12.     {
  13.         myDelegate2 = new delegatePrintoutProcess(updatePrintoutMethod);
  14.         myThread = new Thread(new ThreadStart(ThreadFunction));
  15.         myThread.Start();  
  16.     }
  17.     public void updatePrintoutMethod(string text)
  18.     {
  19.  
  20.        // this.richTextBox1.Text = text;
  21.     }
  22.     private void ThreadFunction()
  23.     {
  24.         parseFile myThreadClassObject = new parseFile(this);
  25.         myThreadClassObject.getFilePath = filePath;
  26.         myThreadClassObject.Run();
  27.  
  28.  
  29.     }
  30. }
  31.        
  32. namespace ETL
  33.  {
  34.     public class parseFile
  35.     {
  36.         Form1 myFormControl1;
  37.     public parseFile(Form1 myForm)
  38.     {
  39.         //get a handle on the main form
  40.         myFormControl1 = myForm;
  41.     }
  42.     String myString;
  43.     public void Run()
  44.     {
  45.  
  46.         for (int i = 1; i <= 5; i++)
  47.         {
  48.             myString = "Step number " + i.ToString() + " executed";
  49.             Thread.Sleep(400);
  50.             // Execute the specified delegate on the thread that owns
  51.             // 'myFormControl1' control's underlying window handle with
  52.             // the specified list of arguments.
  53.             myFormControl1.Invoke(myFormControl1.myDelegate,
  54.                                    new Object[] { myString }); //error here
  55.         }
  56.     }
  57.   }