본문 바로가기

C#35

[C#] ConcurrentDictionary의 컬렉션 수정 오류 발생 여부 테스트 소스 코드: using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp1 { internal class Program { static ConcurrentDictionary a = new ConcurrentDictionary(); static void Main(string[] args) { new Thread(f) { IsBackground = true}.Start(); Thread.Sleep(100); foreac.. 2023. 11. 6.
[C#] 서버 시간 가져오기 class Program { static void Main(string[] args) { Console.WriteLine(GetServerDateTime().ToUniversalTime().AddHours(9)); } public static DateTime GetServerDateTime() { //WebRequest 객체로 사이트 접속 해당 날짜와 시간을 로컬 형태의 포맷으로 리턴 일자에 담는다. using (var response = WebRequest.Create("http://kiwoom.com").GetResponse()) return DateTime.ParseExact(response.Headers["date"], "ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureI.. 2023. 10. 18.
lock using System; using System.Threading; namespace d { class a { static void Main() { new Thread(Thread1).Start(); new Thread(Thread2).Start(); } static void Thread1() { while (true) { Thread.Sleep(500); f(); } } static void Thread2() { while (true) { Thread.Sleep(500); f(); } } static object locker = new object(); static void f() { lock (locker) { Console.WriteLine("hello world!" + DateTime.Now); .. 2023. 7. 2.
NumericUpDown.Value 실시간 동기화하기 NumericUpDown.ValueChanged Event (System.Windows.Forms) | Microsoft Learn NumericUpDown.ValueChanged Event (System.Windows.Forms) Occurs when the Value property has been changed in some way. learn.microsoft.com 에 따르면, Remarks For the ValueChanged event to occur, the Value property can be changed in code, by clicking the up or down button, or by the user entering a new value that is read by the c.. 2023. 6. 4.
파일 읽고 쓰기의 비효율성 using System; using System.Threading; using System.IO; using System.Diagnostics; namespace TEST { internal class Program { private static void Main(string[] args) { var stopwatch = Stopwatch.StartNew(); int filee = 0; for(int i = 1; i 2023. 5. 27.
IsXValueIndexed WinForms chart에서 Series 들어가서 IsXValueIndex를 True로 설정해놓으면 주식 캔들 차트가 장이 열리지 않은 날에 공백을 두는 현상을 막아준다. before after 근데 유심히 보다보니 이상한 점이 있다. 주식 차트가 좌우 반대가 되어버렸다. 그렇다. 날짜 순이 아니라 Points 배열에 추가된 순으로 차트가 그려진다. 그래서 저런 경우에는 추가하는 순서를 반대로 해 줘야 한다... 참고로 어떻게 양봉 음봉 색깔 칠했는지 궁금한 사람이 있다면, 양봉일 경우 DataPoint.Color를 Red로 정하고, 음봉일 경우 Blue로 정하는, 색을 개별적으로 지정하는 식으로 했다고 답하겠다. 2023. 5. 23.
class vs struct 이 코드 하나에 class와 struct의 차이가 담겨있다. using System; namespace TEST { internal class Person { public int age; } internal struct Apple { public int brix; } internal class Program { private static void Main(string[] args) { Person a = new Person { age = 10 }; Person b = a; b.age = 15; Console.WriteLine(a.age); Apple c = new Apple { brix = 20 }; Apple d = c; d.brix = 40; Console.WriteLine(c.brix); } } }.. 2023. 5. 18.
C#) KHOpenAPI 한글 안 깨지게 하는 방법 Windows에서 Windows display language를 한국어가 아닌 다른 언어로 설정하면 한글이 깨진다. 그리고 KHOpenAPI는 대부분의 메소드가 한글에 의존하는 API다. 영어로 display language를 설정해놓은 사람한테 한국어로 바꿔달라고 요청하는 수 밖에 없나? 했는데... 해결책을 찾았다! System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ko-KR"); 프로그램 시작할 때 저 코드를 호출하면 된다. 2023. 5. 18.
WinForms Chart - 0부터 시작하지 않게 하기 주식 차트 그릴 때 0부터 시작하는 게 상당히 거슬린다. 주가가 10만 원이어도 저 옵션이 True면 무조건 0부터 시작한다. 2023. 5. 15.
[C# Windows] System.IO.Path.GetTempPath 쓰지 마라. Path.GetTempPath Method (System.IO) | Microsoft Learn Path.GetTempPath Method (System.IO) Returns the path of the current user's temporary folder. learn.microsoft.com 위 문서에 따르면 해당 Method의 동작 원리는 아래와 같다. (리눅스는 내 알 바 아니니 Windows만 쓰겠다.) The path specified by the TMP environment variable. The path specified by the TEMP environment variable. The path specified by the USERPROFILE environment variable... 2023. 5. 9.