110,534
社区成员
发帖
与我相关
我的任务
分享
From f = new From();
Thread t = new Thread(monitoringFile);
public void monitoring(){
while(true){
if(xxx){
sd();
}
}
public void sd(){
//这里杀毒,但是如何才能讲杀毒的进度推送到 进度条上,我用委托,委托貌似穿参数挺复杂,
//准备启动一个线程去更新进度条,结果界面老死。
}
麻烦C# 板的大牛 指点一下。
private void Form1_Load(object sender, EventArgs e)
{
Thread mt = new Thread(monitorListView);
mt.Start();
}
private void monitorListView()
{
while (isavle)
{
if (nvColletion.Count > 0)
{
newSDpro();
}
}
}
public void newSDpro()
{
if (nvColletion.Count > 0)
{
String sdPath = Properties.Settings.Default.sdPath;
String logPath = Properties.Settings.Default.logPath;
//MessageBox.Show("得到的杀毒软件路径:" + sdPath);
if (sdPath == null || sdPath.Equals(""))
{
MessageBox.Show("杀毒软件未配置,请点击左下角的配置杀毒软件!!");
return;
}
if(logPath == null || logPath.Equals("")){
MessageBox.Show("日志文件路径尚未配置");
return;
}
string time = DateTime.Now.ToString();
string filename = DateTime.Now.ToLongDateString().ToString() + ".log";
string filepath = logPath + "\\" + filename;
if (!IsFileReady(filepath))
{
Thread.Sleep(100);
}
FileStream f = new FileStream(filepath, FileMode.OpenOrCreate | FileMode.Append);
ProcessStartInfo pinfo = new ProcessStartInfo(sdPath);
pinfo.UseShellExecute = false;
pinfo.RedirectStandardOutput = true;
pinfo.CreateNoWindow = true;
pinfo.WindowStyle = ProcessWindowStyle.Hidden;
StreamWriter sw = new StreamWriter(f);
Dictionary<String, String>.Enumerator enumerator = nvColletion.GetEnumerator();
while (enumerator.MoveNext())
{
String sourFile = enumerator.Current.Key;
if (sdPath.EndsWith("ecls.exe"))
{
pinfo.Arguments = "-aind " + sourFile;
}
else
{
pinfo.Arguments = "scan " + sourFile;
}
proc = Process.Start(pinfo);
DirectoryInfo di = new DirectoryInfo(sourFile);
if(di.Exists){
value = di.GetFiles().Length;
}else{
value = nvColletion.Count;
}
Thread pThread = new Thread();
pThread.Start();
while (!proc.HasExited)
{
String line = proc.StandardOutput.ReadLine();
sw.WriteLine(line);
sw.Flush();
}
sw.Close();
procbarvalue++;
String destFile = nvColletion[sourFile];
if (di.Exists)
{
String tmp = sourFile.Substring(sourFile.LastIndexOf("\\"));
destFile += tmp;
CopyFolder(sourFile, destFile);
}
else
{
if (!destFile.EndsWith("\\"))
{
destFile += "\\";
}
try{
File.Copy(sourFile, destFile + Path.GetFileName(sourFile), true);
}catch(IOException){
MessageBox.Show("文件复制出错,可能是文件已经损坏");
}
}
nvColletion.Remove(sourFile);
procbarvalue = 0;
break;
}
}
else
{
MessageBox.Show("选择要传输的文件");
return;
}
}