d

[C#] 서버 상태 체크

C# 2016. 8. 31. 08:42

서버가 살아 있나 죽어 있나를 확인해볼 수 있는 소스

 

 

 

'C#' 카테고리의 다른 글

[Windows Service] 디버깅  (0) 2016.08.05
[Windows Service] 파일 읽기  (0) 2016.07.14
[C#] 파일 경로  (0) 2016.07.14
[C#] ini 파일 모든 섹션 & 키 값 읽기  (0) 2016.07.08
[C#] DataGridView 크기 조절  (0) 2016.07.08
블로그 이미지

_Able

,

[Windows Service] 디버깅

C# 2016. 8. 5. 13:28

윈도우 서비스를 개발할 때 디버깅을 할 수 있는 방법

 

1. System.Diagnostics.Debugger.Launch()

 

프로그램을 돌다가 해당 구문을 만나면 Visual Stuido 와 연결되어 디버깅 모드로 진입할 수가 있다. 주의할 점은 서비스를 설치할 때의 소스와 디버그 모드에 진입할 때의 소스는 서로 동일해야 하며 수정되지 않은 상태이어야 한다.

 

원하는 지점에 해당 구문을 넣은 채로 서비스를 빌드 하고 설치하여 실행 시킨다면 디버그 모드에 진입할 수가 있다.

 

 

 

2. 디버그 모드 - 프로세스 연결

 

해당 기능은 Visual Studio 에서 제공되는 기능으로 다른 곳에서 제공 해주는지는 모르겠다. 위 방법과 마찬가지로 소스는 수정되지 않은 상태에서 서비스가 오류가 나지 않고 잘 돌아간다면 VS 에서 연결이 가능하다.

 

 

 

 

위와 같이 프로세스 목록이 뜨며 연결을 누르면 디버그모드에 진입 한다.

'C#' 카테고리의 다른 글

[C#] 서버 상태 체크  (0) 2016.08.31
[Windows Service] 파일 읽기  (0) 2016.07.14
[C#] 파일 경로  (0) 2016.07.14
[C#] ini 파일 모든 섹션 & 키 값 읽기  (0) 2016.07.08
[C#] DataGridView 크기 조절  (0) 2016.07.08
블로그 이미지

_Able

,

[Windows Service] 파일 읽기

C# 2016. 7. 14. 14:18

Window Service를 작성할 때는 C# 에서 파일 읽기 와는 약간 다른 AppDomain.CurrentDomain.BaseDirectory 함수가 존재 한다. 

 

의미는 약간 다른데 실행파일의 위치라는 의미 보다 윈도우 서비스 파일이 설치된 디렉토리를 의미 한다는게 더 정확한 표현이다.

 

설치되는 디렉토리에 읽기 원하는 파일을 넣어 두고 파일을 읽으면 잘 돌아간다.

 

TIP. 설치 프로젝트에 읽을 파일을 추가 시켜 놓으면 같이 설치된다.

'C#' 카테고리의 다른 글

[C#] 서버 상태 체크  (0) 2016.08.31
[Windows Service] 디버깅  (0) 2016.08.05
[C#] 파일 경로  (0) 2016.07.14
[C#] ini 파일 모든 섹션 & 키 값 읽기  (0) 2016.07.08
[C#] DataGridView 크기 조절  (0) 2016.07.08
블로그 이미지

_Able

,

[C#] 파일 경로

C# 2016. 7. 14. 13:59

C# 에서 파일경로를 설정할 때 쓰이는 명렁어가 있다. 절대경로를 이용하여 파일을 읽을 수도 있지만 파일의 위치는 컴퓨터마다 다르므로 올바른 방법은 아니다.

 

Application.StartupPath 명령어는 응용프로그램이 실행되는 위치의 경로를 반환한다.

 

 

이렇게 작성한 다음 읽으려는 파일을 응용프로그램이 있는 디렉토리에 같이 놔두면 잘 읽힌다.

 

'C#' 카테고리의 다른 글

[C#] 서버 상태 체크  (0) 2016.08.31
[Windows Service] 디버깅  (0) 2016.08.05
[Windows Service] 파일 읽기  (0) 2016.07.14
[C#] ini 파일 모든 섹션 & 키 값 읽기  (0) 2016.07.08
[C#] DataGridView 크기 조절  (0) 2016.07.08
블로그 이미지

_Able

,

ini 파일 안의 모든 section 값과 해당하는 section의 모든 key 값을 한번에 가져오기 위한 소스

 

Form 클래스 안에

 

        [DllImport("kernel32")]
        static extern int GetPrivateProfileString(string Section, string Key,
               string Value, StringBuilder Result, int Size, string FileName);

     
        [DllImport("kernel32")]
        static extern int GetPrivateProfileString(string Section, int Key,
               string Value, [MarshalAs(UnmanagedType.LPArray)] byte[] Result,
               int Size, string FileName);


        [DllImport("kernel32")]
        static extern int GetPrivateProfileString(int Section, string Key,
               string Value, [MarshalAs(UnmanagedType.LPArray)] byte[] Result,
               int Size, string FileName);

 

        public string path;

 

        public string[] GetSectionNames()  // ini 파일 안의 모든 section 이름 가져오기
        {
            for (int maxsize = 500; true; maxsize *= 2)
            {
                byte[] bytes = new byte[maxsize];
                int size = GetPrivateProfileString(0, "", "", bytes, maxsize, path);

            
                if (size < maxsize - 2)
                {
                    string Selected = Encoding.ASCII.GetString(bytes, 0, size - (size > 0 ? 1 : 0));
                    return Selected.Split(new char[] { '\0' });
                }
            }
        }  

 

        public string[] GetEntryNames(string section)   // 해당 section 안의 모든 키 값 가져오기
        {
            for (int maxsize = 500; true; maxsize *= 2)
            {
                byte[] bytes = new byte[maxsize];
                int size = GetPrivateProfileString(section, 0, "", bytes, maxsize, path);

                if (size < maxsize - 2)
                {
                    string entries = Encoding.ASCII.GetString(bytes, 0, size - (size > 0 ? 1 : 0));
                    return entries.Split(new char[] { '\0' });
                }
            }
        }  

'C#' 카테고리의 다른 글

[C#] 서버 상태 체크  (0) 2016.08.31
[Windows Service] 디버깅  (0) 2016.08.05
[Windows Service] 파일 읽기  (0) 2016.07.14
[C#] 파일 경로  (0) 2016.07.14
[C#] DataGridView 크기 조절  (0) 2016.07.08
블로그 이미지

_Able

,

DataGridView 를 DataTable 크기에 맞춰 조정 하고 싶을 때

 

dataGridView.Height = dataGridView.Rows.GetRowsHeight(DataGridViewElementStates.None) + dataGridView.ColumnHeadersHeight + 2;

dataGridView.Width = dataGridView.Columns.GetColumnsWidth(DataGridViewElementStates.None) + dataGridView.RowHeadersWidth + 2;

'C#' 카테고리의 다른 글

[C#] 서버 상태 체크  (0) 2016.08.31
[Windows Service] 디버깅  (0) 2016.08.05
[Windows Service] 파일 읽기  (0) 2016.07.14
[C#] 파일 경로  (0) 2016.07.14
[C#] ini 파일 모든 섹션 & 키 값 읽기  (0) 2016.07.08
블로그 이미지

_Able

,