C# 쓰레드를 위한 ConcurrentDictionary

2021. 3. 21. 23:23· Windows
반응형

.NET Framework 4.0부터 사용가능

다중쓰레드 안정성 보장

Dictionary보다 속도는 느림

 

Dictionary와 ConcurrentDictionary 다중 쓰레드 테스트

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
 
namespace ConsoleApp1
{
 
    public class Program
    {
        static Dictionary<string, int> _mydic = new Dictionary<string, int>();
        static ConcurrentDictionary<string, int> _mydictConcu = new ConcurrentDictionary<string, int>();
        static void Main()
        {
            Thread mythread1 = new Thread(new ThreadStart(InsertData));
            Thread mythread2 = new Thread(new ThreadStart(InsertData));
            mythread1.Start();
            mythread2.Start();
            mythread1.Join();
            mythread2.Join();
            Thread mythread11 = new Thread(new ThreadStart(InsertDataConcu));
            Thread mythread21 = new Thread(new ThreadStart(InsertDataConcu));
            mythread11.Start();
            mythread21.Start();
            mythread11.Join();
            mythread21.Join();
            Console.WriteLine(string.Format("Result in Dictionary : {0}", _mydic.Values.Count));
            Console.WriteLine("********************************************");
            Console.WriteLine(string.Format("Result in Concurrent Dictionary : {0}", _mydictConcu.Values.Count));
            Console.ReadKey();
        }
        static void InsertData()
        {
            for (int i = 0; i < 100; i++)
            {
                _mydic.Add(Guid.NewGuid().ToString(), i);
            }
        }
        static void InsertDataConcu()
        {
            for (int i = 0; i < 100; i++)
            {
                _mydictConcu.TryAdd(Guid.NewGuid().ToString(), i);
            }
        }
    }
 
}
 
Colored by Color Scripter
cs

 

 

 

https://www.c-sharpcorner.com/article/concurrentdictionary-in-c-sharp/

 

ConcurrentDictionary In C#

In this article, you will learn about ConcurrentDictionary in C#.

www.c-sharpcorner.com

 

저작자표시 (새창열림)

'Windows' 카테고리의 다른 글

ARP Scan Console  (0) 2021.04.03
Color Property  (0) 2021.04.03
C# TableLayoutPanel MouseMove event 마우스 올렸을때 셀 색상변경  (0) 2020.11.10
C# 특정일 기준으로 요일(7일) 나열방법  (0) 2020.11.04
C# 투명 폼  (0) 2020.11.04
'Windows' 카테고리의 다른 글
  • ARP Scan Console
  • Color Property
  • C# TableLayoutPanel MouseMove event 마우스 올렸을때 셀 색상변경
  • C# 특정일 기준으로 요일(7일) 나열방법
zosystem
zosystem
몇 달만 지나도 가물가물해서 만든 곳
zosystem
동방노트
zosystem manage
전체
오늘
어제
  • 분류 전체보기 (277)
    • Linux (90)
      • 기본명령어&팁 (13)
      • 설치 및 셋팅 (16)
      • 네트워크보안 (5)
      • Samba&NFS (6)
      • 모니터링 (3)
      • Apache&nginx (5)
      • MySQL (2)
      • PHP (0)
      • Cloud (29)
      • Shell (1)
      • RAID (1)
      • PLEX (2)
      • Python (5)
      • Docker (2)
    • Windows (22)
    • Windows Server (9)
    • IoT (1)
    • 데이타베이스 (1)
    • 잡다한 개발팁 (19)
    • 개발유틸리티 (7)
    • 컴퓨터관리 (127)

블로그 메뉴

  • 홈

공지사항

인기 글

태그

  • openmediavault 7
  • 서버 팬 소음
  • selenium
  • Python
  • 프린터
  • 그래픽카드 드라이버 이슈
  • ap
  • 바탕 화면 아이콘 설정 단축키
  • omv7
  • amd 드라이버 이슈
  • phpmyadmin 접근제어
  • portainer
  • synology firewall
  • fail2ban
  • docker
  • 시놀로지 그누보드5 설치
  • 원격 데스크톱 연결
  • RDP
  • OpenMediaVault
  • PID
  • 프린터 방화벽
  • OMV
  • rsync
  • Printer
  • CCTV
  • synology phpmyadmin
  • IP Camera
  • fpc케이블
  • nt530u4e-e3b
  • mysql_connect() error

최근 댓글

최근 글

hELLO · Designed By 정상우.v4.2.1
zosystem
C# 쓰레드를 위한 ConcurrentDictionary
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.