这是我的代码:
DateTime.Now.AddMinutes(55).ToString("dd/MM/yyyy HH:mm:ss")
Run Code Online (Sandbox Code Playgroud)
我从该代码中获得的字符串是:
"16.09.2013 19:45:03"
Run Code Online (Sandbox Code Playgroud)
问题是,为什么字符串不是我提供的格式?
我不知道如何解决我的问题.我不时会收到错误:"进程无法访问文件'xxxx',因为它正被另一个进程使用".
这是我发生错误的方法:
private static void write_history(int index, int time_in_sec, int[] sent_resources)
{
string filepath = "Config\\xxx.txt";
int writing_index = 0;
if (File.Exists(filepath))
{
System.Threading.Thread.Sleep(5000);
StreamReader reader = new StreamReader(new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read));
string temp = reader.ReadToEnd();
reader.Close();
for (int i = 0; i < 20; i++)
{
if (temp.IndexOf("<hst_" + i.ToString() + ">") == -1)
{
writing_index = i;
break;
}
}
}
System.Threading.Thread.Sleep(5000);
// write to the file
StreamWriter writer = new StreamWriter(filepath, true);
writer.WriteLine("<hst_" + writing_index.ToString() + …Run Code Online (Sandbox Code Playgroud) 我有一些奇怪的问题(对我而言).
有一个应用程序是Windows窗体应用程序"firstapp.exe".还有另一个应用程序,也是Windows窗体应用程序"launcher.exe".并且有一个名为"server.exe"的控制台应用程序.
firstapp和启动器都在同一目录中.在该目录中还有一个"Config"文件夹,其中包含一些其他文件.
我用来从firstapp的config文件夹中读取一个文件的代码:
StreamReader reader = new StreamReader("Config\\launcher.txt");
string readed_config = reader.ReadToEnd();
reader.Close();
Run Code Online (Sandbox Code Playgroud)
如果我使用启动器(使用process.start)运行firstapp应用程序,一切都很顺利.当我使用控制台应用程序运行它时,它与firstapp不在同一目录中,我从代码部分(上面发布)中获取"目录未找到异常".
我该如何解决这个问题?为什么控制台应用程序将自己的路径添加到应该独立运行的另一个应用程