Mit program fryser
HejJeg har et lille problem. når jeg vil ha mit program til at tag backup af vise af mine filer, fryser den og efterfølgende vender tilbage til normal efter ca. 1 min.
Hvilket vil umuliggøre muligheden for en progressbar. Da softwaret først er normalt når den er færdig.
Min kode:
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.Security.Principal;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string qum = System.Windows.Forms.SystemInformation.UserName;
hl1.Text = "Kan være flere minutter om at kopiere.";
pb1.Visible = false;
Creator.Text = "Tilhører: EIHP";
}
private void label1_Click(object sender, EventArgs e)
{
string CreatorURL = "http://www.domain.dk";
System.Diagnostics.Process.Start(CreatorURL);
}
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
button2.Enabled = false;
pb1.Visible = true;
// pb1 er progressbar
string srcPath = "C:\\Users\\%username%";
string dstPath = "\\HRS.local\\dfs\\Employees\\%username%\\backup";
string sourcePathq1 = srcPath + "\\AppData\\Roaming\\Microsoft\\Sticky Notes";
cf(sourcePathq1, dstPath + "\\stickynotes\\");
string sourcePathq2 = srcPath + "\\Favorites";
cf(sourcePathq2, dstPath + "\\favoritter\\");
string sourcePathq3 = srcPath + "\\Desktop";
cf(sourcePathq3, dstPath + "\\skrivebord\\");
hl1.Text = "Færdig";
button1.Enabled = true;
button2.Enabled = true;
pb1.Visible = false;
// pb1 er progressbar
}
private void button2_Click(object sender, EventArgs e)
{
button1.Enabled = false;
button2.Enabled = false;
pb1.Visible = true;
// pb1 er progressbar
}
public static void cf(string Src, string Dst)
{
String[] Files;
if (Dst[Dst.Length - 1] != Path.DirectorySeparatorChar)
Dst += Path.DirectorySeparatorChar;
if (!Directory.Exists(Dst)) Directory.CreateDirectory(Dst);
Files = Directory.GetFileSystemEntries(Src);
foreach (string Element in Files)
{
// Sub directories
if (Directory.Exists(Element))
cf(Element, Dst + Path.GetFileName(Element));
// Files in directory
else
File.Copy(Element, Dst + Path.GetFileName(Element), true);
}
}
}
}