Programming/c# & winform2021. 10. 20. 14:13

abort는 그냥 죽어라! (보장은 안함) 라는 느낌이라면

join은 죽어줄때 까지 기다려 줄께~! 인데

코드 예제를 보면 abort는 서비스로 구성된 while 루프를 죽이고 있고

join은 일회성 쓰레드를 죽이는 예제로 설명되어 있는걸 보면..

맘편하게 abort로 죽어! 해야하려나?

 

[링크 : https://docs.microsoft.com/ko-kr/dotnet/standard/threading/destroying-threads]

 

쓰레드 보다는 간접적인 방법을 쓰라고 권장 -_ㅠ

.NET Framework 4부터 다중 스레딩을 사용하는 권장 방법은 TPL(작업 병렬 라이브러리)  PLINQ(병렬 LINQ)를 사용하는 것입니다. 자세한 내용은 병렬 프로그래밍을 참조하세요.

[링크 : https://docs.microsoft.com/ko-kr/dotnet/standard/threading/threads-and-threading]

 

 .NET Core는 Thread.Abort 메서드를 지원하지 않습니다. .NET Core에서 강제로 타사 코드 실행을 종료해야 하는 경우 별도의 프로세스에서 실행하고 Process.Kill를 사용합니다.

[링크 : https://docs.microsoft.com/ko-kr/dotnet/standard/threading/using-threads-and-threading]

 

obsolete를 사용되지 않는으로 해석해버렸군.

아무튼 abort는 .net 5.0 이후에서는 컴파일 경고가 뜬다고 하니

반강제적으로 TPL이나 PLINQ로 가게 만들려는 정책인듯?

이 메서드는 사용되지 않습니다. .NET 5.0 이상 버전에서이 메서드를 호출 하면 컴파일 타임 경고가 생성 됩니다. 이 메서드는 PlatformNotSupportedException 런타임에 .net 5.0 이상 및 .Net Core에서을 throw 합니다.

[링크 : https://docs.microsoft.com/ko-kr/dotnet/api/system.threading.thread.abort?view=net-5.0]

 

using System;
using System.Threading;

public class Example
{
   static Thread thread1, thread2;
   
   public static void Main()
   {
      thread1 = new Thread(ThreadProc);
      thread1.Name = "Thread1";
      thread1.Start();
      
      thread2 = new Thread(ThreadProc);
      thread2.Name = "Thread2";
      thread2.Start();   
   }

   private static void ThreadProc()
   {
      Console.WriteLine("\nCurrent thread: {0}", Thread.CurrentThread.Name);
      if (Thread.CurrentThread.Name == "Thread1" && 
          thread2.ThreadState != ThreadState.Unstarted)
         if (thread2.Join(TimeSpan.FromSeconds(2)))
            Console.WriteLine("Thread2 has termminated.");
         else
            Console.WriteLine("The timeout has elapsed and Thread1 will resume.");   
      
      Thread.Sleep(4000);
      Console.WriteLine("\nCurrent thread: {0}", Thread.CurrentThread.Name);
      Console.WriteLine("Thread1: {0}", thread1.ThreadState);
      Console.WriteLine("Thread2: {0}\n", thread2.ThreadState);
   }
}

[링크 : https://docs.microsoft.com/ko-kr/dotnet/api/system.threading.thread.join?view=net-5.0]

 

using System;
using System.Threading;

class Test
{
    public static void Main()
    {
        Thread newThread  = new Thread(new ThreadStart(TestMethod));
        newThread.Start();
        Thread.Sleep(1000);

        // Abort newThread.
        Console.WriteLine("Main aborting new thread.");
        newThread.Abort("Information from Main.");

        // Wait for the thread to terminate.
        newThread.Join();
        Console.WriteLine("New thread terminated - Main exiting.");
    }

    static void TestMethod()
    {
        try
        {
            while(true)
            {
                Console.WriteLine("New thread running.");
                Thread.Sleep(1000);
            }
        }
        catch(ThreadAbortException abortException)
        {
            Console.WriteLine((string)abortException.ExceptionState);
        }
    }
}

[링크 : https://docs.microsoft.com/ko-kr/dotnet/api/system.threading.thread.abort?view=net-5.0]

'Programming > c# & winform' 카테고리의 다른 글

c# postgresql 패키지  (0) 2022.04.27
winform udp 소켓 여러개  (0) 2021.10.26
Dispatcher / Control BeginInvoke()  (0) 2021.10.20
this.BeginInvoke()가 느려!  (0) 2021.10.20
크로스 스레드 작업이 잘못되었습니다  (0) 2021.10.19
Posted by 구차니
Programming/c# & winform2021. 10. 20. 12:21

'Programming > c# & winform' 카테고리의 다른 글

winform udp 소켓 여러개  (0) 2021.10.26
c# thread  (0) 2021.10.20
this.BeginInvoke()가 느려!  (0) 2021.10.20
크로스 스레드 작업이 잘못되었습니다  (0) 2021.10.19
winform 쓰레드와 소켓  (0) 2021.10.18
Posted by 구차니
Programming/c# & winform2021. 10. 20. 10:19

invoke()는 동기(blocking) 방식이고

begininvoke()는 비동기인데 메시지 큐에 넣어놓고 하는거 치고는 너무 느린데...

단순하게 키보드로 1,2,3,4 순서로 누르는 것 조차도 커버 못할 정도면

메시지 큐가 아니라 invoke 시퀀스에 먼가 문제가 있는 걸지도?

 

[링크 : https://stackoverflow.com/questions/50084323]

[링크 : https://yunhyeon.tistory.com/379]

'Programming > c# & winform' 카테고리의 다른 글

c# thread  (0) 2021.10.20
Dispatcher / Control BeginInvoke()  (0) 2021.10.20
크로스 스레드 작업이 잘못되었습니다  (0) 2021.10.19
winform 쓰레드와 소켓  (0) 2021.10.18
C# 트레이 아이콘 예제  (0) 2021.10.18
Posted by 구차니
Programming/wasm2021. 10. 19. 18:25

이름만 듣고 먼 뻘짓인가 싶었는데

동영상 보고 나니 호기심이 가서 검색.

 

일단.. 내가 알던 그 어셈같은 뻘짓(?)은 아니고

다른 언어로 부터 한번 컴파일 해서 사용하는거라 상세(?) 언어 자체를 직접 구현할 필요는 없이

c나 rust, go 등으로 부터 컴파일 해서 나온 결과만을 쓰는 거라 문법 자체를 따로 공부할 이유는 없을 듯.

 

단지 그러한 기술이 있고 어떤 언어를 통해서 변환을 어떻게 하면 된다 정도만 알면 될 듯하다.

 

[링크 : https://webassembly.org/getting-started/developers-guide/]

[링크 : https://tech.kakao.com/2021/05/17/frontend-growth-08/]

[링크 : https://en.wikipedia.org/wiki/WebAssembly]

'Programming > wasm' 카테고리의 다른 글

wasm text 와 binary 상호변환  (0) 2021.10.26
emcc wasm 빌드  (0) 2021.10.25
wasm from c, cpp  (0) 2021.10.24
wasm  (0) 2021.10.22
wasm emcc  (0) 2018.10.24
Posted by 구차니
Programming/c# & winform2021. 10. 19. 17:18

쓰레드 만들어서 하는걸 해보지 않았으니 이런 경험을 다해보네 ㅠㅠ

(너무 늦었어!!!)

 

일단 UDP 소켓을 통해서 받은걸 UI에 쓰려고 했는데

UDP 소켓은 별도의 쓰레드로 생성해서 blocking 함수를 통해 받아오게 되어있다 보니

어떻게 보면 당연한거지만..

UDP 소켓 쓰레드에서 UI의 컨트롤 함수로 직접 접근을 하면 아래와 같은 에러가 발생하면서 죽어 버린다.

정확하게는 그냥 원인불명으로 죽어서, 디버거로 찍고 실행하니 이런 메시지가 발생한다.

System.InvalidOperationException: '크로스 스레드 작업이 잘못되었습니다. 'textBox1' 컨트롤이 자신이 만들어진 스레드가 아닌 스레드에서 액세스되었습니다.'

 

아무튼 아래와 같은 부분이 있어서 머야? 하고 빼버리긴 했었는데

이런 이유로 쓰레드에서 UI 쓰레드로 던지기 위해 invoke 해주는 함수를 거쳐서 던질 수 있게 하는 듯

this.BeginInvoke((Action<string>)DataReceivedUI, receivedMsg);

        private void DataReceivedUI(string data)
        {
            textBox1.Text += (data + "\n");
        }

[링크 : https://m.blog.naver.com/iconms1/221956474085]

 

근데, 키보드막 연타로 때리니 버벅댄다.

긴 걸 한번에 붙이는건 문제 없는걸 봐서, 저 함수를 이용하는건 쓰면 안 될 지도?

'Programming > c# & winform' 카테고리의 다른 글

Dispatcher / Control BeginInvoke()  (0) 2021.10.20
this.BeginInvoke()가 느려!  (0) 2021.10.20
winform 쓰레드와 소켓  (0) 2021.10.18
C# 트레이 아이콘 예제  (0) 2021.10.18
CGridctrl setitembkcolour  (0) 2021.09.01
Posted by 구차니
Programming/c# & winform2021. 10. 18. 16:20

'Programming > c# & winform' 카테고리의 다른 글

this.BeginInvoke()가 느려!  (0) 2021.10.20
크로스 스레드 작업이 잘못되었습니다  (0) 2021.10.19
C# 트레이 아이콘 예제  (0) 2021.10.18
CGridctrl setitembkcolour  (0) 2021.09.01
mfcimagegallery  (0) 2021.08.30
Posted by 구차니
Programming/c# & winform2021. 10. 18. 11:56

'Programming > c# & winform' 카테고리의 다른 글

크로스 스레드 작업이 잘못되었습니다  (0) 2021.10.19
winform 쓰레드와 소켓  (0) 2021.10.18
CGridctrl setitembkcolour  (0) 2021.09.01
mfcimagegallery  (0) 2021.08.30
std::vector , std:set  (0) 2021.08.25
Posted by 구차니
Programming/C++ STL2021. 10. 2. 23:17

아래의 함수가 가장 눈에 잘 들어 오는 듯?

fill(vec.begin(), vec.end(), value);

 

[링크 : https://hini7.tistory.com/66]

'Programming > C++ STL' 카테고리의 다른 글

cpp static_cast<type>  (0) 2023.02.09
::open()  (0) 2021.11.10
cpp 부모타입으로 업 캐스팅 된 객체의 원래 클래스 알기  (0) 2021.09.30
cpp string 관련  (0) 2019.06.10
cpp stringstream << 연산자  (0) 2019.05.24
Posted by 구차니
Programming/C++ STL2021. 9. 30. 14:58

dynamic_cast<>() 를 통해 변환해보면 원래 타입을 알 수 있음.

[링크 : https://stackoverflow.com/questions/307765/how-do-i-check-if-an-objects-type-is-a-particular-subclass-in-c]

 

+

해보니 완벽하게 탐지하지는 못하는 듯..

'Programming > C++ STL' 카테고리의 다른 글

::open()  (0) 2021.11.10
vector 값 비우기  (0) 2021.10.02
cpp string 관련  (0) 2019.06.10
cpp stringstream << 연산자  (0) 2019.05.24
c++ 함수 인자 기본값  (0) 2017.11.08
Posted by 구차니
Programming/c# & winform2021. 9. 1. 16:20

3번째 인자인 색상을 생략하면 clear 색상으로 칠해진다.

그나저나.. color랑 colour을 섞어 쓴 이유는 멀까 -ㅁ-?

 

[링크 : http://egloos.zum.com/potato1004/v/5874308]

'Programming > c# & winform' 카테고리의 다른 글

winform 쓰레드와 소켓  (0) 2021.10.18
C# 트레이 아이콘 예제  (0) 2021.10.18
mfcimagegallery  (0) 2021.08.30
std::vector , std:set  (0) 2021.08.25
ribbon with gallery  (0) 2021.08.24
Posted by 구차니