Programming/c# & winform2022. 4. 27. 17:00

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

c# postgresql 패키지  (0) 2022.04.27
winform udp 소켓 여러개  (0) 2021.10.26
c# thread  (0) 2021.10.20
Dispatcher / Control BeginInvoke()  (0) 2021.10.20
this.BeginInvoke()가 느려!  (0) 2021.10.20
Posted by 구차니
Programming/c# & winform2022. 4. 27. 15:52

azure 예제에서도 나올정도면 가장 믿을만 하려나?

[링크 : https://www.nuget.org/packages/Npgsql/]

 

[링크 : http://www.gisdeveloper.co.kr/?p=5963]

[링크 : https://dodo1054.tistory.com/22]

[링크 : https://docs.microsoft.com/ko-kr/azure/postgresql/connect-csharp]

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

window USB VID,PID enumeration  (0) 2022.04.27
winform udp 소켓 여러개  (0) 2021.10.26
c# thread  (0) 2021.10.20
Dispatcher / Control BeginInvoke()  (0) 2021.10.20
this.BeginInvoke()가 느려!  (0) 2021.10.20
Posted by 구차니
Programming/c# & winform2021. 10. 26. 18:07

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

window USB VID,PID enumeration  (0) 2022.04.27
c# postgresql 패키지  (0) 2022.04.27
c# thread  (0) 2021.10.20
Dispatcher / Control BeginInvoke()  (0) 2021.10.20
this.BeginInvoke()가 느려!  (0) 2021.10.20
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 구차니
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# & 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 구차니