我在C#中没有很好的经验并且在MS中处理过服务但是我在一个更大的过程中有很多次调用的代码:
private static void InvokeRTF2HTMLParseApplication(string rtfFileName, string htmlFinalFileName)
{
string strRTFParseApplicationPath = AppDomain.CurrentDomain.BaseDirectory + "rtfParse2Xhtml.exe";
if (File.Exists(strRTFParseApplicationPath))
{
try
{
Process process = new Process();
process.StartInfo.FileName = strRTFParseApplicationPath;
process.StartInfo.Arguments = "\"" + rtfFileName + "\"" + " " + "\"" + htmlFinalFileName + "\"";
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.Start();
process.WaitForExit();
}
catch( Exception e )
{
using (StreamWriter w = File.AppendText("\\log.txt"))
{
Log(e.ToString(), w);
}
}
}
}
这会调用rtfParse2Xhtml.exe
文件来解析rft并保存为html文件。
随机(我可以确认)有时我会收到下一条错误消息:
此过程在process.Start()
行停止,然后中断。
这是我的事件日志消息错误:
Application: rtfParse2Xhtml.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.IOException
Stack:
at System.IO.__Error.WinIOError(Int32, System.String)
at System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean)
at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess)
at EmpRtf2Xhtml.rtfParseInput..ctor(System.String)
at EmpRtf2Xhtml.rtfParse2Xhtml.Main(System.String[])
在命令行中,我使用rtfParse2Xhtml.exe
调用转换过程,并在程序停止时使用相同的rtf
文件,一切正常。因此,我认为rtf
文件中不存在阻止转换的奇怪字符或符号。
我还认为这不是文件夹权限,因为这总是发生在同一个文件夹上,多次,而不是相同的测试用例。 这种情况发生在Windows 7计算机和Windows Server 2012R2中。
我的rtfParse2Xhtml
代码是:
if (File.Exists(args[1]))
{
Console.WriteLine("RtfParser: Update Files " + args[1] + ".");
}
string fileName= args[0];
string fileName2 = args[1];
rtfParse2Xhtml.fInput = new rtfParseInput(fileName);
rtfParse2Xhtml.fOutput = new rtfParseOutput(fileName2, false, Encoding.GetEncoding(28591));
Console.WriteLine("RtfParser: Start");
int num = rtfParse2Xhtml.TrataGeral();
Console.WriteLine("".PadRight(70, '-'));
Console.WriteLine("RtfParser: Stop with RC=" + num);
result = num;
rtfParseInput
构造函数类:
public rtfParseInput(string fileName)
{
this.fileInput = new FileStream(fileName, FileMode.Open, FileAccess.Read);
}