i have been writing up a small app to do some stuff in WPF. at one point i have a file copy with a progressbar. it works fine if i have it in a normal windows form. but will lock up in the wpf window. they both get the job done and the file makes it so it is just something with the progress bar. can anyone help me with this?
C#
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.progressBar1.Location = new System.Drawing.Point(12, 12);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(689, 81);
this.progressBar1.TabIndex = 0;
public void CopyFile(string src, string dst)
{
System.IO.FileStream SourceFile = new FileStream(src, FileMode.Open, FileAccess.Read, FileShare.None);
System.IO.FileStream DestFile = new FileStream(dst, FileMode.Append, FileAccess.Write, FileShare.None);
byte[] buffer = new byte[16384000];
progressBar1.Maximum = (int)SourceFile.Length / 16384000;
progressBar1.Minimum = 0;
progressBar1.Step = 1;
while (true)
{
int read = SourceFile.Read(buffer, 0, buffer.Length);
if (read <= 0)
break;
DestFile.Write(buffer, 0, read);
progressBar1.PerformStep();
}
this.Close();
}
WPF
<ProgressBar Margin="16,10,22,16" Name="progressBar1" />
public void CopyFile(string src, string dst)
{
System.IO.FileStream SourceFile = new FileStream(src, FileMode.Open, FileAccess.Read, FileShare.None);
System.IO.FileStream DestFile = new FileStream(dst, FileMode.Append, FileAccess.Write, FileShare.None);
byte[] buffer = new byte[16384000];
progressBar1.Maximum = (int)SourceFile.Length / 16384000;
progressBar1.Minimum = 0;
while (true)
{
int read = SourceFile.Read(buffer, 0, buffer.Length);
if (read <= 0)
break;
DestFile.Write(buffer, 0, read);
progressBar1.Value += 1;
}
this.Close();
}