how to call the method in thread with aruguments and return some value

Posted by ratty on Stack Overflow See other posts from Stack Overflow or by ratty
Published on 2010-04-15T05:38:39Z Indexed on 2010/04/15 5:43 UTC
Read the original article Hit count: 245

Filed under:
|

i like to call the method in thread with aruguments and return some value here example

class Program { static void Main() { Stopwatch stop = new Stopwatch(); stop.Start(); Thread FirstThread = new Thread(new ThreadStart(Fun1)); Thread SecondThread = new Thread(new ThreadStart(Fun2)); FirstThread.Start(); SecondThread.Start();

    }
    public static void Fun1()
    {
        for (int i = 1; i <= 1000; i++)
        {
            Console.WriteLine("Fun1 writes:{0}", i);
        }
    }
    public static void Fun2()
    {
        for (int i = 1000; i >= 6; i--)
        {
            Console.WriteLine("Fun2 writes:{0}", i);
        }
    }

}

i know this above example run successfully but if method fun1 like this

public int fun1(int i)
{
for (int n = i; n >= i+10; n++)
        {
            Console.WriteLine("Fun2 writes:{0}", i);
        }
}

then how can i call this in thread. Is it possible .Any body Help for me

© Stack Overflow or respective owner

Related posts about c#

Related posts about threads