'2021/10/20'에 해당되는 글 4건

  1. 2021.10.20 코로나 백신 후유증?
  2. 2021.10.20 c# thread
  3. 2021.10.20 Dispatcher / Control BeginInvoke()
  4. 2021.10.20 this.BeginInvoke()가 느려!

아내님 5일째 열이 나서

오늘 주사맞은 병원갔더니 대학병원가서 진료받아 보라고 해서 갔는데

코로나 검사결과지 들고 와야 함

그게 아니면 119로 응급실 들어와야 가능

그것도 아니면 6시간 기다릴래?

 

라는데 이게 무슨 우리 별이 짖는 소리도 아니고 -_-

'개소리 왈왈 > 육아관련 주저리' 카테고리의 다른 글

휴가 3일차  (0) 2021.10.29
휴가 2일차  (0) 2021.10.28
화이자 2차 접종  (0) 2021.10.08
내일 백신 2차!  (0) 2021.10.07
코로나 3273  (0) 2021.09.25
Posted by 구차니
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 구차니