开发者

fetch data from multiple database server at same time using multithreading c#

i want to call same database procedure from C# programe to multiple database server at same time.how we can implement using multithereading or any alternative method.

e.g. server1 takes 2 min,server2 takes 3 min,server3 takes 1 min

total time taken=6 min.

i want to run C# programe to run database procedure parallel to all server , so that i can get result 开发者_开发百科within 2 min.


Sounds reasonable. You could create a method for each algorithm which performs the job you need. Then use ThreadPool to invoke this task in parallel.


if we have to use same function then i would have to implement multiple time? like this:

using System;
using System.Threading;
public class mythread
{
    public static void Main()
    {
        // Queue the task.
        Console.WriteLine(DateTime.Now);
        ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc1));
        //ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc2));

        Console.WriteLine("Main thread does some work, then sleeps.");
        // If you comment out the Sleep, the main thread exits before
        // the thread pool task runs.  The thread pool uses background
        // threads, which do not keep the application running.  (This
        // is a simple example of a race condition.)
        Thread.Sleep(1000);

        Console.WriteLine("Main thread exits.");
        Console.WriteLine(DateTime.Now);
        Console.Read();
    }

    // This thread procedure performs the task.
    static void ThreadProc1(object obj)
    {
        // No state object was passed to QueueUserWorkItem, so 
        // stateInfo is null.
        Console.WriteLine("Hello world!!,this is ONE.");
    }
    static void ThreadProc2(object obj)
    {
        // No state object was passed to QueueUserWorkItem, so 
        // stateInfo is null.
        Console.WriteLine("Hello world!!,this is TWO.");
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜