欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c#并行編程示例分享

 更新時間:2014年01月24日 14:25:52   作者:  
這篇文章主要介紹了c#并行編程示例,大家直接看下面的代碼吧

ParallelTest.cs

復制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace ParallelTest
{
    class ParallelTest
    {
        private static int Timed_Message(String arg_Message, int arg_Interval)
        {
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Source {0} - Cycle {1} for Interval {2}", arg_Message, i, arg_Interval);
                Thread.Sleep(1000 * arg_Interval);
            }

            Console.WriteLine("{0} - Complete", arg_Message);
            return 0;
        }

        static void Main(string[] args)
        {
            int RetCode = 0;
            Task RedistributionTask = new Task(() => RetCode = Timed_Message("Five ", 4));
            RedistributionTask.Start();
            Task AltRedistributionTask = new Task(() => RetCode = Timed_Message("Three ", 2));
            AltRedistributionTask.Start();
            //Timed_Message("Main", 6);

            // wait for input before exiting
            Console.WriteLine("Press enter to finish after both [Complete] messages appear.");
            Console.ReadLine();
        }
    }
}

輸出結果

復制代碼 代碼如下:

Press enter to finish after both [Complete] messages appear.
Source Five  - Cycle 0 for Interval 4
Source Three  - Cycle 0 for Interval 2
Source Three  - Cycle 1 for Interval 2
Source Five  - Cycle 1 for Interval 4
Source Three  - Cycle 2 for Interval 2
Source Three  - Cycle 3 for Interval 2
Source Five  - Cycle 2 for Interval 4
Source Three  - Cycle 4 for Interval 2
Source Three  - Cycle 5 for Interval 2
Source Five  - Cycle 3 for Interval 4
Source Three  - Cycle 6 for Interval 2
Source Three  - Cycle 7 for Interval 2
Source Five  - Cycle 4 for Interval 4
Source Three  - Cycle 8 for Interval 2
Source Three  - Cycle 9 for Interval 2
Source Five  - Cycle 5 for Interval 4
Three  - Complete
Source Five  - Cycle 6 for Interval 4
Source Five  - Cycle 7 for Interval 4
Source Five  - Cycle 8 for Interval 4
Source Five  - Cycle 9 for Interval 4
Five  - Complete

相關文章

  • 分析C# Dictionary的實現(xiàn)原理

    分析C# Dictionary的實現(xiàn)原理

    對于C#中的Dictionary類相信大家都不陌生,這是一個Collection(集合)類型,可以通過Key/Value(鍵值對的形式來存放數(shù)據(jù);該類最大的優(yōu)點就是它查找元素的時間復雜度接近O(1)。那么什么樣的設計能使得Dictionary類實現(xiàn)O(1)的時間復雜度呢
    2021-06-06
  • c#生成縮略圖的實現(xiàn)方法

    c#生成縮略圖的實現(xiàn)方法

    c#生成縮略圖的實現(xiàn)方法,需要的朋友可以參考一下
    2013-04-04
  • C#中委托用法實例詳解

    C#中委托用法實例詳解

    這篇文章主要介紹了C#中委托用法,以實例形式較為詳細的分析了C#中委托的概念與使用技巧,需要的朋友可以參考下
    2015-06-06
  • c#項目將dll打包到exe中的步驟

    c#項目將dll打包到exe中的步驟

    這篇文章主要介紹了c#項目將dll打包到exe中的步驟,幫助大家更好的理解和學習使用c#,感興趣的朋友可以了解下
    2021-04-04
  • 字符串替換Replace僅替換第一個字符串匹配項

    字符串替換Replace僅替換第一個字符串匹配項

    C#里面的String.Replace(string,string)方法替換的時候是替換所有的匹配項,我們需要只替換第一個匹配項,寫一個方法來實現(xiàn)這個功能
    2013-12-12
  • C#開發(fā)Windows UWP系列之對話框MessageDialog和ContentDialog

    C#開發(fā)Windows UWP系列之對話框MessageDialog和ContentDialog

    這篇文章介紹了C#開發(fā)Windows UWP系列之對話框MessageDialog和ContentDialog,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-06-06
  • C#實現(xiàn)控制臺飛行棋小游戲

    C#實現(xiàn)控制臺飛行棋小游戲

    這篇文章主要為大家詳細介紹了C#實現(xiàn)控制臺飛行棋小游戲,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下的相關資料
    2021-07-07
  • C#設計模式編程中運用適配器模式結構實戰(zhàn)演練

    C#設計模式編程中運用適配器模式結構實戰(zhàn)演練

    這篇文章主要介紹了C#設計模式編程中運用適配器模式結構實戰(zhàn)演練,并總結了適配器模式的優(yōu)缺點和適用場景以及.NET框架中的應用,需要的朋友可以參考下
    2016-02-02
  • C#短消息提示窗口位置及窗口大小詳解

    C#短消息提示窗口位置及窗口大小詳解

    在我們的生活中無論是使用QQ,360安全衛(wèi)士等軟件的過程中,經(jīng)常會遇到從右下方的托盤處彈出一個消息提示窗,比如新聞,產(chǎn)品更新等內(nèi)容,下面這篇文章主要給大家介紹了關于C#短消息提示窗口位置及窗口大小的相關資料,需要的朋友可以參考下
    2022-12-12
  • C# using語法糖圖文詳解

    C# using語法糖圖文詳解

    這篇文章主要給大家介紹了關于C# using語法糖的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-01-01

最新評論