如: private void btnJieYa_Click(object sender, EventArgs e)
{
Thread thread = new Thread(new ThreadStart(RARExtract));
thread.Start();
}请问RARExtract后面的参数该如何处理!!
public static bool RARExtract(string path, string rarPath, string rarName)
{
bool flag = false;
string rarexe;
RegistryKey regkey;
Object regvalue;
string cmd;
ProcessStartInfo startinfo;
Process process;
try
{
regkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
regvalue = regkey.GetValue("");
rarexe = regvalue.ToString();
regkey.Close();
// rarexe = rarexe.Substring(1, rarexe.Length - 7); Directory.CreateDirectory(path);
//解压缩命令,相当于在要压缩文件(rarName)上点右键->WinRAR->解压到当前文件夹
cmd = string.Format("x {0} {1} -y",
rarName,
path);
startinfo = new ProcessStartInfo();
startinfo.FileName = rarexe;
startinfo.Arguments = cmd;
startinfo.WindowStyle = ProcessWindowStyle.Hidden; startinfo.WorkingDirectory = rarPath;
process = new Process();
process.StartInfo = startinfo;
process.Start();
process.WaitForExit();
if (process.HasExited)
{
flag = true;
}
process.Close();
MessageBox.Show("解压完成!");
}
catch (Exception e)
{
throw e;
}
return flag;
}
{
Thread thread = new Thread(new ThreadStart(RARExtract));
thread.Start();
}请问RARExtract后面的参数该如何处理!!
public static bool RARExtract(string path, string rarPath, string rarName)
{
bool flag = false;
string rarexe;
RegistryKey regkey;
Object regvalue;
string cmd;
ProcessStartInfo startinfo;
Process process;
try
{
regkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
regvalue = regkey.GetValue("");
rarexe = regvalue.ToString();
regkey.Close();
// rarexe = rarexe.Substring(1, rarexe.Length - 7); Directory.CreateDirectory(path);
//解压缩命令,相当于在要压缩文件(rarName)上点右键->WinRAR->解压到当前文件夹
cmd = string.Format("x {0} {1} -y",
rarName,
path);
startinfo = new ProcessStartInfo();
startinfo.FileName = rarexe;
startinfo.Arguments = cmd;
startinfo.WindowStyle = ProcessWindowStyle.Hidden; startinfo.WorkingDirectory = rarPath;
process = new Process();
process.StartInfo = startinfo;
process.Start();
process.WaitForExit();
if (process.HasExited)
{
flag = true;
}
process.Close();
MessageBox.Show("解压完成!");
}
catch (Exception e)
{
throw e;
}
return flag;
}
解决方案 »
- C#(录音)中CaptureBuffer类的使用,(缓冲区数据读取问题)
- 怎样用键盘控制VS2005向导生成的BindingNavigator的前进、后退?
- listview里照片点击弹出新窗体显示其放大照片传值问题,100分急救!!!!!!
- XML问题
- 【Gridveiw】设置"标题"不换行怎样设置~
- 动态设置Datagrid列宽?
- 可否让Visual Studio 2002关联的.net Framework为1.1版?
- 如何用C#实现数据库的数据统计(用图形显示统计结果)?
- 请问c#中有类似于variant、OldVariant这样的变量类型吗???
- 未能找到引用的组件“DevExpress.Data.v9.1”。
- 如何将config文件作为xml读取
- 请教正则高手,下面这三个是什么意思?
Thread(ParameterizedThreadStart) 就可以传递参数了,是object的参数,你可以将你的那些参数封装成一个类,实例化该类,赋值参数后,传递过去!
public Thread(
ParameterizedThreadStart start
)
public delegate void ParameterizedThreadStart(
Object obj
)
using System.Threading;public class Work
{
public static void Main()
{
// To start a thread using a shared thread procedure, use
// the class name and method name when you create the
// ParameterizedThreadStart delegate. C# infers the
// appropriate delegate creation syntax:
// new ParameterizedThreadStart(Work.DoWork)
//
Thread newThread = new Thread(Work.DoWork); // Use the overload of the Start method that has a
// parameter of type Object. You can create an object that
// contains several pieces of data, or you can pass any
// reference type or value type. The following code passes
// the integer value 42.
//
newThread.Start(42); // To start a thread using an instance method for the thread
// procedure, use the instance variable and method name when
// you create the ParameterizedThreadStart delegate. C# infers
// the appropriate delegate creation syntax:
// new ParameterizedThreadStart(w.DoMoreWork)
//
Work w = new Work();
newThread = new Thread(w.DoMoreWork); // Pass an object containing data for the thread.
//
newThread.Start("The answer.");
} public static void DoWork(object data)
{
Console.WriteLine("Static thread procedure. Data='{0}'",
data);
}
public void DoMoreWork(object data)
{
Console.WriteLine("Instance thread procedure. Data='{0}'",
data);
}
}