windbg - 닷넷 응용 프로그램의 메모리 누수 분석

windbg - 닷넷 응용 프로그램의 메모리 누수 분석
[출처] windbg - 닷넷 응용 프로그램의 메모리 누수 분석|작성자 techshare

출처: http://blog.naver.com/PostView.nhn?blogId=techshare&logNo=221461195700&parentCategoryNo=&categoryNo=&viewDate=&isShowPopularPosts=false&from=postList
image.png

image.png

prompt 매크로
image.png
copy /Y "$(TargetDir)$(TargetName).*" "$(SolutionDir)\02.Launcher\GSCM.Launcher\bin\Debug$(TargetName).*"

image.png

MSSQL MERGE
image.png

    MERGE dbo.[SCP_MST_GRADE_MAPPING] AS T
        USING 
        (
            SELECT 
            C_ACTIVE_FLAG
            , C_GRAD_SURFNM
            , C_MODE
            , C_EXTENSION
            , C_GRADE
            , C_MODEL_GUBUN
            , C_MODEL_BIG_GUBUN
            , C_CREATED_BY   
            FROM   #RESULTS                
        ) AS S
        ON 
        (      
                  T.[GRADE_SURFNM]        = S.C_GRAD_SURFNM        COLLATE Korean_Wansung_CI_AS
              AND T.GRADE                = S.C_GRADE            COLLATE Korean_Wansung_CI_AS
              AND T.EXTENSION            = S.C_EXTENSION        COLLATE Korean_Wansung_CI_AS

        )
        WHEN MATCHED AND C_ACTIVE_FLAG = 'M'
          THEN
            UPDATE 
            SET      
                  T.APPLICATION            = C_MODE          
                , T.[MODEL_GUBUN]        = C_MODEL_GUBUN  
                , T.[MODEL_BIG_GUBUN]    = C_MODEL_BIG_GUBUN                            
                , T.LAST_UPDATED_BY        = C_CREATED_BY  
                , T.LAST_UPDATE_DATE    = SYSDATETIME()
        WHEN MATCHED AND C_ACTIVE_FLAG = 'D'
        THEN
            DELETE
        WHEN NOT MATCHED 
        THEN
            INSERT 
            (
                [GRADE_SURFNM]
              , GRADE     
              ,[EXTENSION]
              ,[APPLICATION]
              ,[MODEL_GUBUN]
              ,[MODEL_BIG_GUBUN]    
              , CREATED_BY
              , CREATION_DATE
              , LAST_UPDATED_BY
              , LAST_UPDATE_DATE 
            )
            VALUES
            (
                S.C_GRAD_SURFNM
              , S.C_GRADE
              , S.C_EXTENSION
              , S.C_MODE           
              , S.C_MODEL_GUBUN
              , S.C_MODEL_BIG_GUBUN    
              , S.C_CREATED_BY  
              , SYSDATETIME()
              , S.C_CREATED_BY  
              , SYSDATETIME()
            );  

image.png

동적참조
image.png

C# task 중지 종료
image.png
실행중인 Task 중지법

  CancellationTokenSource cts = new CancellationTokenSource();
       CancellationToken token = cts.Token;

       Task myTask = Task.Factory.StartNew(() =>
       {
            for(...)
           {
               token.ThrowIfCancellationRequested();

                //Body of for loop.
           }
       }, token);

       // ... elsewhere ...
       cts.Cancel();

출처: https://m.blog.naver.com/PostView.nhn?blogId=burin&logNo=40152498179&proxyReferer=https%3A%2F%2Fwww.google.co.kr%2F

image.png
C# task 중지 종료

//task 시작
CancellationTokenSource cts = null; private void button6_Click(object sender, EventArgs e) { cts = new CancellationTokenSource(); CancellationToken token = cts.Token; myTask2 = Task<int>.Run(() => { for (int i = 0; i < 10000; i++) { token.ThrowIfCancellationRequested(); Console.WriteLine("DoSomething : {0}", i); Thread.Sleep(30); } } , token); }

//task 중지
private void button4_Click(object sender, EventArgs e) { if (myTask2 != null && cts != null) { cts.Cancel(); } }

//task 상태확인
private void button5_Click(object sender, EventArgs e) { if (myTask2 != null && cts != null) { if (myTask2.IsCompleted) { MessageBox.Show("Complete"); } else { MessageBox.Show("ing"); } } }

참고: https://m.blog.naver.com/PostView.nhn?blogId=burin&logNo=40152498179&proxyReferer=https%3A%2F%2Fwww.google.co.kr%2F

C# 실행중인 Task 중지법
실행중인 Task 중지법 CancellationTokenSource cts = new CancellationTokenSource(); Cancellati...
m.blog.naver.com
[출처] C# task 중지 종료|작성자 은기

출처: https://blog.naver.com/PostView.nhn?blogId=axlovelee&logNo=221408555241&from=search&redirect=Log&widgetTypeCall=true&topReferer=https%3A%2F%2Fsearch.naver.com%2Fsearch.naver%3Fsm%3Dtab_hty.top%26where%3Dpost%26query%3Dc%2523%2BTask.Run%26oquery%3Dabort%26tqi%3DUb51Usp0IWlsscbtVHossssssI8-361028&directAccess=false

image.png
Enum - 참조 관련 이슈
image.png

https://blog.naver.com/blog_-/221461015357

image.png
C# 리플렉션을 이용한 Delegate 넘기기

image.png

A.exe에서 B.dll을 컴파일시 참조하지 않고 동적으로 참조할 때,

B.dll에 있는 특정 클래스 메서드의 파라미터(Delegate)를 넘길때 방법입니다.

리플렉션을 이용해서 대리자 개체를 생성 후 Invoke 파라미터에 넘겨주었습니다.

A.exe

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DelegateReflaction
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InvokeTest();
}

    private void InvokeTest()
    {
        string dllFilePath =@"D:\Work\Project\Test\DelegateReflaction\TestLibrary\bin\Debug\TestLibrary.dll";
        Assembly assembly = Assembly.LoadFile(dllFilePath);

        Type formType = assembly.GetType("TestLibrary.ChiForm");

        //Child 델리게이트 타입 가져오기
        Type deleType = assembly.GetTypes().Single(a => a.Name == "CallbackDelegate");


        //현재 클래스의 Callback 메서드 정보 가져오기
        MethodInfo callBackMethodInfo = this.GetType().GetMethod("Callback", BindingFlags.NonPublic |BindingFlags.Instance, null, new Type[] { typeof(string) }, null);

        //Child의 CallbackDelegate Delegate를 이용해서 Deleagte 생성
        Delegate callbackMethod = Delegate.CreateDelegate(deleType, this, callBackMethodInfo);

        //Child 폼 생성
        Form form = Activator.CreateInstance(formType) as Form;

        //Child의 DoWork 메서드 가져오기
        MethodInfo doworkMethodInfo = formType.GetMethod("DoWork");

        //파라미터 생성
        object[] parameters = new object[2];
        parameters[0] = "test~";
        parameters[1] = callbackMethod;

        //Child Dowork 메서드 호출
        doworkMethodInfo.Invoke(form, parameters);

        form.Show();
    }

    void Callback(string msg)
    {
        MessageBox.Show(msg);
    }
}

}

B.dll

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestLibrary
{
public class ChiForm : Form
{
public delegate void CallbackDelegate(string status);

    public ChiForm()
    {
        InitializeComponent();
    }

    public void DoWork(string param, CallbackDelegate callback)
    {
        callback("status");
    }

    private void InitializeComponent()
    {
        this.SuspendLayout();
        //
        // ChiForm
        //
        this.ClientSize = new System.Drawing.Size(284, 262);
        this.Name = "ChiForm";
        this.Text = "ChildForm";
        this.ResumeLayout(false);

    }
}

}

출처: https://ehdrn.tistory.com/453 [동구의 블로그]

출처: https://ehdrn.tistory.com/453