Multi threading progress bar

Introduction: Threads enable execution of different pieces of code at the same time. You may encounter the terms: synchronous, sequential or procedural execution, all describing the execution of code one command at a time

Explanation: In multi threading progress bar there is a time scheduler which you can link with your any certain task when it completes your progress bar is fill and show you a message box which tells you about the status of the task. In our example, we will create two threads in C#: Thread 1 and Thread 2, when 1 is finished then 2nd thread is start

here is the code of Multi threading progress bar

CODE:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace progressbar
{
public partial class Form1 : Form
{
delegate void dt(int i);
delegate void dt1();
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Thread objthread = new Thread(runfun);
objthread.Start();
}

public void runfun()
{
for (int i = 0; i <= 100; i++)
{
modifyprogressbar(i);
modifyprogressbar2(100 – i);

}
}
public void modifyprogressbar(int s)
{
if (progressBar1.InvokeRequired)
{
progressBar1.Invoke(new MethodInvoker(delegate
{
progressBar1.Value = s;
Thread.Sleep(100);

}));
}
}

public void modifyprogressbar2(int a)
{
if (progressBar2.InvokeRequired)
{
progressBar2.Invoke(new MethodInvoker(delegate
{
progressBar2.Value=a;
Thread.Sleep(100);
}));

}

}

 
}
}

 

 

Capture