Exacto, el problema esque no puedo sincronizarlos, el hilo que va evaluando la base de datos y realizando la conexion con esta, con el hilo del progressbar...
Como podria hacerlo con un solo hilo??
De pasada (ya que es viernes
) mira este ejemplo:
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.IO;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Thread myThread;
delegate void SetValueCallback(int valor);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
myThread
= new Thread
(new ThreadStart
(listar
)); myThread.Start();
}
private void Form1_Load(object sender, EventArgs e)
{
progressBar1.Minimum = 0;
}
private void listar()
{
int i = 0;
DirectoryInfo dInfo
= new DirectoryInfo
(@"C:\Windows\"); FileInfo[] finfo = dInfo.GetFiles("*.*", SearchOption.AllDirectories);
this.SetMax(finfo.Length);
foreach (FileInfo f in finfo)
{
this.SetValue(i += 1);
System.Threading.Thread.Sleep(50);
}
}
private void SetValue(int valor)
{
if (this.InvokeRequired)
{
SetValueCallback d
= new SetValueCallback
(SetValue
); this.Invoke(d,
new object[] { valor
}); }
else
{
this.progressBar1.Value = valor;
}
}
private void SetMax(int valor)
{
if (this.InvokeRequired)
{
SetValueCallback d
= new SetValueCallback
(SetMax
); this.Invoke(d,
new object[] { valor
}); }
else
{
this.progressBar1.Maximum = valor;
}
}
}
}
Lista una carpeta, luego el número de archivos en la misma pasa a ser el valor máximo del PB, por último va recorriendo cada archivo de la carpeta y al hacerlo va cambiando el valor del PB hasta llegar al máximo.
Puedes modificarlo y mejorarlo para lo que necesitas.