🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# / lock i anlayacak ornek copy paste yap c# a(3 progressbar 1 tane button 1 tane textbox)

1-) C# -

lock i anlayacak ornek copy paste yap c# a(3 progressbar 1 tane button 1 tane textbox)

 

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 losda

{

    public partial class Form1 : Form

    {

        public object locker;

        public Form1()

        {

            InitializeComponent();

            locker = new object();

        }

        Thread t1;

        private void prog1()

        {

            lock (locker)

            {

                while (progressBar1.Value < 100)

                {

                    progressBar1.Value += 1;

                    textBox1.Text += "X";

                    Thread.Sleep(30);

 

 

                }

            }

            

        }

        private void prog2()

        {

            lock (locker)

            {

                while (progressBar2.Value < 100)

            {

                progressBar2.Value += 1;

                textBox1.Text += "y";

                Thread.Sleep(30);

 

 

                }

            }

        }

        private void prog3()

        {

            

                while (progressBar3.Value < 100)

            {

                progressBar3.Value += 1;

                textBox1.Text += "z";

                Thread.Sleep(30);

 

 

            }

            

        }

        private void btn_hepsi_Click(object sender, EventArgs e)

        {

            System.Windows.Forms.Form.CheckForIllegalCrossThreadCalls = false;//threadlarda çakışma olursa ben hallederim

 

            t1 = new Thread(prog1);//metod da "()" yoktur

            Thread t2 = new Thread(prog2);//metod da "()" yoktur

            Thread t3 = new Thread(prog3);//metod da "()" yoktur

            t1.Start();

            t2.Start();

            t3.Start();

        }

    }

}

 2021 Ocak 18 Pazartesi
 469