我有一个问题,我试图使用parallel.for()将一些文件加载到数据库中.我的问题是,传递给数据库函数的文件ID在某种程度上是不正确的.也就是说,数据库返回错误的数据.我试图通过使用并发字典来验证这一点,以添加有和没有并行的id/name对.在我看来,循环结束后列表应该是相同的.但他们不是.这模拟了我正在以非常简单的方式做的事情.
这有意义吗?:
class Program
{
ConcurrentDictionary<int, string> _cd = new ConcurrentDictionary<int, string>();
static void Main()
{
//simulate the situation
int[] idList = new int[] {1, 8, 12, 19, 25, 99};
string[] fileList = new string[] {"file1", "file8", "file12", "file19", "file25", "file99"};
//run in serial first
ProcessFiles(idList, fileList);
//write out pairs to text file
foreach (var item in _cd)
{
var key = _cd.key;
var val = _cd.value;
string line = string.Format("fileId is {0} and fileName is {1}", key, val);
File.AppendAllText(@"c:\serial.txt", …Run Code Online (Sandbox Code Playgroud) 我的控制台应用程序检查网络驱动器上是否存在文件,并在不存在时记录消息.今天我将我的应用程序部署到QA计算机,File.Exists()已经为存在的文件返回false.我通过Windows任务调度程序运行应用程序.当我从命令行运行它似乎工作正常.但不管怎样,我现在都不相信它.有没有人看过这种行为或有任何见解?:
Using System.IO;
private static void Main()
{
var fileName = @"x:\folder\file1.txt"; //be a network share
If (!File.Exists(fileName)
{
LogMessage("File is not on disk.");
}
else
{
LogMessage("File is on disk.");
}
}
Run Code Online (Sandbox Code Playgroud)