Implementing multithreading with functions having parameters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Anish G
    New Member
    • Nov 2006
    • 18

    Implementing multithreading with functions having parameters

    Hi,

    I am new to working on threading. I need to implement multithreading for calling four functions (each functions are having parameters) in different threads so that i can improve the performance of the software. Can anybody help me with sample code for implementing this?

    Thanks,
    Anish.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by Anish G
    Hi,

    I am new to working on threading. I need to implement multithreading for calling four functions (each functions are having parameters) in different threads so that i can improve the performance of the software. Can anybody help me with sample code for implementing this?

    Thanks,
    Anish.
    What have you tried so far?
    Have you seen the two Sticky links at the top of this forum?
    The second Sticky link on important links and answers to commonly asked questions contains a bunch of links to resources that may help you out.

    Specifically check out the MSDN Library.

    Hope this helps!

    -Frinny

    Comment

    • chinu
      New Member
      • Jun 2007
      • 36

      #3
      Originally posted by Frinavale
      What have you tried so far?
      Have you seen the two Sticky links at the top of this forum?
      The second Sticky link on important links and answers to commonly asked questions contains a bunch of links to resources that may help you out.

      Specifically check out the MSDN Library.

      Hope this helps!

      -Frinny
      try something like below
      class MyThread
      {
      public int Data1;
      public string Data2;
      public void Fn1(object y)
      {
      Data1 = (int)y;
      Console.WriteLi ne(Data1);
      Thread.Sleep(50 00);
      }
      public void Fn2(object x)
      {
      Data2 = (string)x;
      Console.WriteLi ne(Data2);
      }
      }

      class Program
      {
      static void Main(string[] args)
      {
      MyThread w = new MyThread();
      w.Data1 = 42;
      w.Data2 = "aa";
      Thread newThread1 = new Thread(new ParameterizedTh readStart(w.Fn1 ));
      Thread newThread2 = new Thread(new ParameterizedTh readStart(w.Fn2 ));
      newThread1.Star t(10);
      newThread2.Star t("test");
      }
      }

      Comment

      Working...