1
I’m creating a system that takes files from a server and copies them to my machine. I work in a software company and as we can not install systems from outside, I decided to create the own. The system is even working, but I’m improving it.
I need to insert a progress bar so that it is possible to track the status of the copy. I created another Form2.Cs window where the bar is, I configured the call from the window, but I’m in doubt when it’s time to make the call from the load bar.
Follows the code:
private void button1_Click(object sender, EventArgs e)
{
//Chamar outra janela
atualizainstaladores2.Form2 barra = new atualizainstaladores2.Form2();
barra.ShowDialog();
if (!Directory.Exists(@"E:\InstaladoresSHOP\Sistemas"))
{
//criar o diretório caso não exista
// copiar de PDV todos os arquivos com .exe no final
Directory.CreateDirectory(@"E:\InstaladoresShop\Sistemas\Shop\PDV");
string[] PDV = Directory.GetFiles(@"C:\Users\thale\Downloads\Sistemas\Sistemas\PDV", "*.exe");
foreach (string item in PDV)
{
File.Copy(item, @"E:\InstaladoresShop\Sistemas\Shop\PDV\" + Path.GetFileName(item));
}
MessageBox.Show("Diretorio PDV atualizado com Sucesso!!");
}
1- Code execution will stop on
ShowDialog
up to the formbarra
be closed, then you can not open it as a modal dialog. 2- During the copy, the screen will be locked. The ideal is that this task is done in another thread, while the progress is displayed on the screen. 3-Take a look at the Backgroundworker, and consider displaying the progress bar in itForm
where the copy is happening.– Rovann Linhalis
I implemented what @Rovannlinhalis commented above in my reply.
– perozzo