自從Jacob和DLL傳出不倫戀之後,雙方家長(Java與微軟)都指責是對方害系統掛掉.
身為Java族系一份子的我,為了讓DLL俯首認罪,低聲下氣向身在微軟族系的近親C#求救.
C#感於自身也是因Java而存在,不吝賜下比李昌鈺還厲害的搜證方式,證明這個DLL不舉~~不!是不能並行處理.
以下是C#使用multi-thread的方式,果然是Java的近親,還不難學:
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace ThreadCallDLL
{
    internal class WorkerClass
    {
        int no;
        public WorkerClass(int no)
        {
            this.no = no;
        }
        public void doWork()
        {
            DateTime start = System.DateTime.Now;
            WAI.EFUnit efUnit = new WAI.EFUnit();
            efUnit.EFX("0.000278012^-1.52e-07^0.000213952^5.47e-05^0.000313124^-5.44e-07^8.5686e-05|-1.52e-07^3.76e-08^2.0732e-06^1.7948e-06^1.4268e-06^5.32e-08^-4.0192e-06|0.000213952^2.0732e-06^0.0003991704^9.74396e-05^0.0003172116^2.0904e-06^-0.0001589804|5.47e-05^1.7948e-06^9.74396e-05^0.0001294984^0.0001933304^2.8836e-06^-0.0001515956|0.000313124^1.4268e-06^0.0003172116^0.0001933304^0.0008101264^2.9116e-06^0.0001632984|-5.44e-07^5.32e-08^2.0904e-06^2.8836e-06^2.9116e-06^8.24e-08^-5.0844e-06|8.5686e-05^-4.0192e-06^-0.0001589804^-0.0001515956^0.0001632984^-5.0844e-06^0.0005928584",
                "0.044366398796|0.0033199812631|0.012640365722|0.011296455712|0.0031603911385|0.0045399589894|0.024171249876");
            // String str = countUnit.GetGReturnXReturn1;
            DateTime end = System.DateTime.Now;
            TimeSpan ts = end - start;
            System.Console.WriteLine(this.no + "=> " + ts.Milliseconds); // + efUnit.GetEFXReturn1);
        }
    }
 
    class Program
    {
        static void Main(string[] args)
        {
            int count = 10;
            int sleep = 100;
            DateTime start = System.DateTime.Now;
            System.Console.WriteLine(start);
            Thread[] threads = new Thread[count];
            for (int i = 0; i < count; i++)
            {
                WorkerClass w = new WorkerClass(i);
                threads[i] = new Thread(new ThreadStart(w.doWork));
                Thread.Sleep(sleep);
                threads[i].Start();
            }
            System.Console.WriteLine("Start OK!!");
            for (int i = 0; i < count; i++)
            {
                threads[i].Join();
            }
            DateTime end = System.DateTime.Now;
            System.Console.WriteLine(end);
            TimeSpan ts = end - start;
            System.Console.WriteLine("Finish=>" + ts.Milliseconds);
            Thread.Sleep(5000);
        }
    }
}
 
arrow
arrow
    全站熱搜

    Jemmy 發表在 痞客邦 留言(1) 人氣()