블로그 이미지
010-9967-0955 보미아빠

카테고리

보미아빠, 석이 (500)
밥벌이 (16)
싸이클 (1)
일상 (1)
Total
Today
Yesterday

달력

« » 2024.3
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

공지사항

최근에 올라온 글

task

카테고리 없음 / 2018. 11. 2. 14:35

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading;

using System.Threading.Tasks;

using System.Windows.Forms;


namespace winform

{

    public partial class Form1 : Form

    {

        DataTable table;

        public Form1()

        {

            InitializeComponent();


        }


        private async void button1_Click(object sender, EventArgs e)

        {

            await Task.Run(() => {


                FillData();


                dataGridView1.InvokeIfRequired(s => {

                    s.ColumnCount = 3;

                    s.Columns[0].Name = "Column1";

                    s.Columns[1].Name = "Column2";

                    s.Columns[2].Name = "Column3";

                    s.Columns[0].Width = 100;

                    s.Columns[1].Width = 100;

                    s.Columns[2].Width = 300;

                    s.RowHeadersVisible = false;

                });


                foreach (DataRow row in table.Rows)

                {

                    dataGridView1.InvokeIfRequired(s => {

                        int n = s.Rows.Add();

                        s.Rows[n].Cells[0].Value = row["Column1"].ToString();

                        s.Rows[n].Cells[1].Value = row["Column2"].ToString();

                        s.Rows[n].Cells[2].Value = row["Column3"].ToString();

                    });

                }

            });

        }

        

        private void FillData()

        {

            table = new DataTable();

            table.Columns.Add("Column1", typeof(string));

            table.Columns.Add("Column2", typeof(string));

            table.Columns.Add("Column3", typeof(string));

            for (int i = 0; i < 1000000; i++)

            {

                table.Rows.Add(i.ToString(), "Indocin", "David");

            }

        }

    }


    public static class ControlHelpers

    {

        public static void InvokeIfRequired<T>(this T control, Action<T> action) where T : ISynchronizeInvoke

        {

            if (control.InvokeRequired)

            {

                control.Invoke(new Action(() => action(control)), null);

            }

            else

            {

                action(control);

            }

        }

    }

}



Posted by 보미아빠
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함