header-img
Info :
728x90

ํผ ๋””์ž์ธ

 

ํผ ๋””์ž์ธ์€ ๊ฐ€๋ณ๊ฒŒ Button 1๊ฐœ์™€ ๊ธ€์„ ์จ์ค„ ๊ณต๊ฐ„์ธ FlowLayoutPanel 1๊ฐœ๋ฅผ ๋„ฃ์–ด์ฃผ์ž

* FlowLayoutPanel ์€ ๋ฌด์–ธ๊ฐ€ ๋™์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•  ๋•Œ ๋งŽ์ด ์‚ฌ์šฉํ•จ 

์˜ˆ๋ฅผ ๋“ค๋ฉด.. ๋ฒ„ํŠผ์ด๋‚˜ ๋ผ๋ฒจ ๊ฐ™์€ ๊ฑธ ๋™์ ์œผ๋กœ ์ถ”๊ฐ€ํ•ด์ค˜์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ

์™œ๋ƒ๋ฉด.. ์ž๋™ ๋ฐฐ์น˜ ๊ธฐ๋Šฅ(?)์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ..  *

์ด ๊ฒƒ์— ๋Œ€ํ•ด์„œ๋Š” ์ฐจํ›„์— ํฌ์ŠคํŒ…์„ ํ•˜๋„๋ก ํ•ด์•ผ๊ฒ ๋‹ค

 

 

<<Form1.Designer.cs>>

namespace Syn_example
{
    partial class Form1
    {
        /// <summary>
        /// ํ•„์ˆ˜ ๋””์ž์ด๋„ˆ ๋ณ€์ˆ˜์ž…๋‹ˆ๋‹ค.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// ์‚ฌ์šฉ ์ค‘์ธ ๋ชจ๋“  ๋ฆฌ์†Œ์Šค๋ฅผ ์ •๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
        /// </summary>
        /// <param name="disposing">๊ด€๋ฆฌ๋˜๋Š” ๋ฆฌ์†Œ์Šค๋ฅผ ์‚ญ์ œํ•ด์•ผ ํ•˜๋ฉด true์ด๊ณ , ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด false์ž…๋‹ˆ๋‹ค.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form ๋””์ž์ด๋„ˆ์—์„œ ์ƒ์„ฑํ•œ ์ฝ”๋“œ

        /// <summary>
        /// ๋””์ž์ด๋„ˆ ์ง€์›์— ํ•„์š”ํ•œ ๋ฉ”์„œ๋“œ์ž…๋‹ˆ๋‹ค. 
        /// ์ด ๋ฉ”์„œ๋“œ์˜ ๋‚ด์šฉ์„ ์ฝ”๋“œ ํŽธ์ง‘๊ธฐ๋กœ ์ˆ˜์ •ํ•˜์ง€ ๋งˆ์„ธ์š”.
        /// </summary>
        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(97, 11);
            this.button1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(358, 62);
            this.button1.TabIndex = 0;
            this.button1.Text = "Button";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // flowLayoutPanel1
            // 
            this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 99);
            this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
            this.flowLayoutPanel1.Name = "flowLayoutPanel1";
            this.flowLayoutPanel1.Size = new System.Drawing.Size(562, 351);
            this.flowLayoutPanel1.TabIndex = 3;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(562, 450);
            this.Controls.Add(this.flowLayoutPanel1);
            this.Controls.Add(this.button1);
            this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
    }
}

 

<<Form1.cs>>

using System;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Syn_example
{
    public partial class Form1 : Form
    {
        int i = 1;
        Random randomObj = new Random();

        public Form1()
        {
            InitializeComponent();
            //minute = randomObj.Next(1000, 10000); 

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Task delay = AsyncFunc();
        }

        public async Task AsyncFunc()
        {
            int minute = randomObj.Next(1000, 10000);
            await Task.Delay(minute);

            Label lbl = new Label();
            lbl.Text = string.Format((i++) + "๋ฒˆ์งธ: " + (minute / 1000) + "์ดˆ");
            flowLayoutPanel1.Controls.Add(lbl);

            minute = 0;
        }


        /*private async Task button1_ClickAsync(object sender, EventArgs e)
        {
            minute = randomObj.Next(1000, 10000);
            //Delay(minute);
            await Task.Delay(1000);

            Label lbl = new Label();
            lbl.Text = String.Format(i++ + "๋ฒˆ์งธ: " + (minute / 1000) + "์ดˆ");
            flowLayoutPanel1.Controls.Add(lbl);
        }*/


        /*private static DateTime Delay(int MS)
        {
            DateTime ThisMoment = DateTime.Now;
            TimeSpan duration = new TimeSpan(0, 0, 0, 0, MS);
            DateTime AfterWards = ThisMoment.Add(duration);

            while (AfterWards >= ThisMoment)
            {
                System.Windows.Forms.Application.DoEvents();
                ThisMoment = DateTime.Now;
            }

            return DateTime.Now;
        }*/

    }
}

 

๋ณ€์ˆ˜๋ฅผ ์–ด๋””์„œ ์ง€์ •ํ•ด์ฃผ๊ณ , ์–ด๋””์„œ ๊ฐ’์„ ์ž…ํ˜€์ฃผ๋ƒ์— ๋”ฐ๋ผ ์‹œ์Šคํ…œ ๊ตฌ๋™์ด ๋‹ค๋ฅด๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ๋จ

๋งˆ๋ƒฅ ์ „์—ญ๋ณ€์ˆ˜๊ฐ€ ๋ฌด๊ธฐ๋Š” ์•„๋‹ˆ๋‹ค ๋ผ๋Š” ๊ฒƒ๋„.... 

 

delay ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด์„œ ์ง„ํ–‰ํ•˜์˜€์œผ๋‚˜...

c#์€ ์• ์ดˆ์— ๋น„๋™๊ธฐ ๊ธฐ๋ฐ˜์ด ์•„๋‹ˆ๊ธฐ์— ๋ญ”๊ฐ€ ์• ๋งคํ•˜๊ฒŒ ๊ธฐ๋Šฅ๊ตฌํ˜„์ด ๋˜๋”๋ผ

 

๋‚˜๋Š” ๋ฒ„ํŠผ ์—ฌ๋Ÿฌ๋ฒˆ ๋ˆŒ๋ €์„ ๋•Œ ๋น„๋™๊ธฐ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•ด์ฃผ๊ณ ,

(๋ช‡ ๋ฒˆ ๋ˆ„๋ฅด๋˜ ์ฒ˜๋ฆฌ๊ฐ€ ๋น„๋™๊ธฐ์ ์œผ๋กœ stack์— ์Œ“์—ฌ์žˆ๋‹ค๊ฐ€ ์ฒ˜๋ฆฌ ๋˜์–ด์•ผ ํ•˜๋Š” case)

๊ทธ๋ž˜์„œ ๊ทธ๋ƒฅ delay ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ async ๋กœ ๋‹ค์‹œ ๊ตฌํ˜„.

 

๋งŒ์•ฝ ์ผ์‹œ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ stack์— ์Œ“์—ฌ์žˆ์–ด์•ผ ํ•˜๋Š” ๊ตฌ์กฐ๊ฐ€ ์•„๋‹ˆ๊ณ  delay๋ฅผ ์ฃผ์–ด์•ผ ํ•œ๋‹ค๋ฉด,

๊ทธ๋ƒฅ ํ•จ์ˆ˜ ์‚ฌ์šฉ์ด ๋” ๊ฐ„ํŽธํ•  ๊ฒƒ ๊ฐ™์Œ..

 

์ƒ๊ฐ๋ณด๋‹ค async๊ฐ€ ์ด๊ฒƒ์ €๊ฒƒ ์‹ ๊ฒฝ ์จ์ค˜์•ผํ•  ๊ฒƒ์ด ๋งŽ๋”๋ผ ... ** ์ถ”๊ฐ€ ํฌ์ŠคํŒ… ํ•˜์ž

 

 

๊ทธ๋ž˜์„œ ์ด ์ฝ”๋“œ์—๋Š” 2๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ๋‹ค ๋“ค์–ด ์žˆ๋‹ค๋Š” ๋ง์”€...

 

์š”๋กœ์ผ€ ์‹œํ–‰๋œ๋‹ค.

c#๋„ ๋ณ‘๋ ฌ(๋น„๋™๊ธฐ์‹)์ด ๊ฐ€๋Šฅํ•˜์ง€๋งŒ.. ์ด๊ฒŒ ๋‚ด๋ถ€์ ์œผ๋กœ ์™„๋ฒฝํ•œ ๋ณ‘๋ ฌ์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ์„๊นŒ?

๋‚ด๋ถ€๊ตฌ์กฐ๊ฐ€ ๊ถ๊ธˆํ•ด์ง๋‹ˆ๋‹ค.. ํƒ๊ตฌํ•˜๊ฒŒ ๋˜๋ฉด ํฌ์ŠคํŒ…์„ ์ถ”๊ฐ€ํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

์•„๋ฌดํŠผ ๋น„๋™๊ธฐ์‹์œผ๋กœ ๋ณด์ด๋Š” ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ ๋ฐฉ๋ฒ• ํ™•์ธ ์˜ˆ์ œ ํ”„๋กœ๊ทธ๋žจ์„ ์Šค์Šค๋กœ ๋งŒ๋“ค์–ด๋ณด์•˜์๋‹ˆ๋‹ค.

 

728x90
๋”๋ณด๊ธฐ
FRONTEND/C#