it-100



 ListView 추가/삭제 ( add / remove / delete / del )




[MainWindow.xaml]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        xmlns:Properties="clr-namespace:WpfApp1.Properties" x:Class="WpfApp1.MainWindow"
        mc:Ignorable="d"
        Title="MainWindow" Height="521.5" Width="572.968">
    <Grid Margin="10">
        <ListView x:Name="ListView01" HorizontalAlignment="Left" Width="448"  Height="461" VerticalAlignment="Top" Margin="87,0,0,0">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Name" Width="200" DisplayMemberBinding="{Binding Name}" />
                    <GridViewColumn Header="Age" Width="100" DisplayMemberBinding="{Binding Age}" />
                </GridView>
            </ListView.View>
        </ListView>
        <Button x:Name="btnADD" Content="ADD" HorizontalAlignment="Left" VerticalAlignment="Top" Width="82" Height="41" Click="btnADD_Click"/>
        <Button x:Name="btn_DEL" Content="DEL" HorizontalAlignment="Left" Height="41" Margin="0,46,0,0" VerticalAlignment="Top" Width="82" Click="btn_DEL_Click"/>
    </Grid>
</Window>
 
cs



[MainWindow.xaml.cs]


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Collections.Generic;
using System.Windows;
namespace WpfApp1
{
    /// <summary>
    /// MainWindow.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        List<Man> items = new List<Man>();
        public class Man
        {
            public string Name { get; set; }
            public int Age { get; set; }
        }
        private void btnADD_Click(object sender, RoutedEventArgs e)
        {
            items.Add(new Man() { Name = "aaa", Age = 555 });
            items.Add(new Man() { Name = "bbb", Age = 444 });
            items.Add(new Man() { Name = "ccc", Age = 333 });
            items.Add(new Man() { Name = "ddd", Age = 222 });
            items.Add(new Man() { Name = "eee", Age = 111 });
            ListView01.ItemsSource = items;
            ListView01.Items.Refresh();
        }
        private void btn_DEL_Click(object sender, RoutedEventArgs e)
        {
            foreach (Man item in ListView01.SelectedItems)
            {
                items.Remove(item);
            }
            ListView01.Items.Refresh();
        }
    }
}
cs




출처: http://insurang.tistory.com/191?category=754858 [it 정보 메모지]


 WPF & C# - 로그파일 만들기 ( LOG )






MainWindows.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
private void btn_input_Click(object sender, RoutedEventArgs e)
{
    LogWrite("버튼클릭");
}
 
private void LogWrite(string str)
{
    string FilePath = Environment.CurrentDirectory + @"\Log\Log_" + DateTime.Today.ToString("yyyyMMdd"+ ".log";
    string DirPath = Environment.CurrentDirectory + @"\Log";
    string temp;
 
    DirectoryInfo di = new DirectoryInfo(DirPath);
    FileInfo fi = new FileInfo(FilePath);
 
    try
    {
        if (!di.Exists) Directory.CreateDirectory(DirPath);
        if (!fi.Exists)
        {
            using (StreamWriter sw = new StreamWriter(FilePath))
            {
                temp = string.Format("[{0}] {1}", DateTime.Now, str);
                sw.WriteLine(temp);
                sw.Close();
            }
        }
        else
        {
            using (StreamWriter sw = File.AppendText(FilePath))
            {
                temp = string.Format("[{0}] {1}", DateTime.Now, str);
                sw.WriteLine(temp);
                sw.Close();
            }
        }
    }
    catch (Exception e)
    {
    }
}
cs





WPF C# - 스레드 Thread - 네임스페이스 ( Threading/ Thread )


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
namespace System.Windows.Threading
{
    //
    // 요약:
    //     호출 가능한 작업 통해 우선 순위에 설명 된 System.Windows.Threading.Dispatcher합니다.
    public enum DispatcherPriority
    {
        //
        // 요약:
        //     열거형 값은-1입니다. 잘못 된 우선 순위입니다.
        Invalid = -1,
        //
        // 요약:
        //     열거형 값은 0입니다. 작업이 처리 되지 않습니다.
        Inactive = 0,
        //
        // 요약:
        //     열거형 값은 1입니다. 시스템이 유휴 상태일 때 작업이 처리 됩니다.
        SystemIdle = 1,
        //
        // 요약:
        //     열거형 값은 2입니다. 응용 프로그램이 유휴 상태일 때 작업이 처리 됩니다.
        ApplicationIdle = 2,
        //
        // 요약:
        //     열거형 값은 3입니다. 백그라운드 작업이 완료 된 후 작업이 처리 됩니다.
        ContextIdle = 3,
        //
        // 요약:
        //     열거형 값은 4입니다. 다른 모든 비 유휴 작업이 완료 된 후 작업이 처리 됩니다.
        Background = 4,
        //
        // 요약:
        //     열거형 값은 5입니다. 작업이 동일한 우선 입력으로 처리 됩니다.
        Input = 5,
        //
        // 요약:
        //     열거형 값은 6입니다. 레이아웃 및 렌더링 끝나면 되기 직전 입력된 우선 순위에서 항목을 처리 하는 작업이 처리 됩니다. 특히이 Loaded
        //     이벤트를 발생 시킬 때 사용 됩니다.
        Loaded = 6,
        //
        // 요약:
        //     열거형 값은 7입니다. 렌더링으로 동일한 우선 순위 처리 하는 작업입니다.
        Render = 7,
        //
        // 요약:
        //     열거형 값은 8입니다. 작업이는 데이터 바인딩과 동일한 우선 순위 처리 됩니다.
        DataBind = 8,
        //
        // 요약:
        //     열거형 값은 9입니다. 작업은 보통 우선 순위로 처리 됩니다. 일반적인 응용 프로그램 우선 순위입니다.
        Normal = 9,
        //
        // 요약:
        //     열거형 값은 10입니다. 작업은 다른 비동기 작업 보다 먼저 처리 됩니다. 가장 높은 우선 순위입니다.
        Send = 10
    }
}
cs


싱글코어(코어 1개), 듀얼(코어 2개), 트리플코어(코어 3개), 쿼드코어(코어 4개), 헥사코어(코어 6개), 옥타코어(코어 8개)

무엇일까? CPU(코어)의 개수이다.

한 PC 에 CPU는 한개 들었지만, 해당 CPU에서 연산처리를 하는 코어라는 것이 개수가 다 다른것이다.


하나의 일을 하나의 코어에게 할당해 줄 수도 있고, 하나의 일을 여러개의 코어에게 같이 할당하여 더 빠르게 처리할 수도 있다.


이와 같은 것이 스레드이다.

흔희들 작업 스레드라는 표현을 많이 한다.

메인 스레드와 새로 생성되는 스레드간에 상호 작용이 원활하도록 해주는 것이다.

프로그램에서도 역시나 세세하게 다 설정해 줄 수 있다.

뒤늦게 나온 개념 만큼이나 다소 복잡하지만 배워두면 분명 더 효율적인 프로그래밍이 가능할거 같아서 메모해 둔다.


위 코드는 WPF의 Threading 의 네임스페이스 이다.

예제는 다음 페이지를 참고해주세요.

각각의 스레드에 적절한 할당을 하기 위해 정의를 내린 부분이니 반드시 알아두고 사용하자^^