Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C语言中的怪异动作循环#_C#_For Loop_Openfiledialog - Fatal编程技术网

C# C语言中的怪异动作循环#

C# C语言中的怪异动作循环#,c#,for-loop,openfiledialog,C#,For Loop,Openfiledialog,注意:我添加了实际的代码片段。只需滚动到末尾。 // files is created by a OpenFileDialog. public void Function(String[] files, ...) { for(int i; i<files.Length; i++) { WriteLine("File " + i + "/" + files.Length + " being processed."); //... process

注意:我添加了实际的代码片段。只需滚动到末尾。

// files is created by a OpenFileDialog.
public void Function(String[] files, ...)
{
    for(int i; i<files.Length; i++)
    {
        WriteLine("File " + i + "/" + files.Length + " being processed.");
        //... processing for a long time and printing information to console ...
    }

    //... print results, e.g.: "Results: bla bla"...
}
然而,我得到的结果是:

-------------------------
File 0/1 being processed.
...lots of output...

Results: bla bla...

File 0/3 being processed.
...lots of output...
File 1/3 being processed.
...lots of output...
File 2/3 being processed.
...lots of output...

Results: bla bla...

File 0/3 being processed.
...lots of output...
File 1/3 being processed.
...lots of output...
File 2/3 being processed.
...lots of output...

Results: bla bla...

File 0/6 being processed.
...lots of output...
File 1/6 being processed.
...lots of output...
File 2/6 being processed.
...lots of output...
File 3/6 being processed.
...lots of output...
-------------------------
当我看到输出时,我在当前循环结束(它运行)之前退出了执行 很长一段时间。)

看起来函数工作正常(它运行files.Length次,然后输出结果。)但是,传递给函数的参数有点错误(有趣的是,函数被多次调用。通常情况下,在这种情况下,它应该只运行一次。我的意思是,脚本文件中的行数决定了上述函数被调用的次数,而脚本文件只包含一行。)该参数(文件数组)来自OpenFileDialog,这意味着我与它无关。我只是将数组传递给函数

我仍在试图理解出现这种奇怪结果的原因。这种情况只发生过一次,但我仍然需要诊断问题;因为我可能会让程序运行几天。它应该可以正常工作

你对这种胡说八道有什么想法吗


上述功能的实际代码:

public String Start(String[] files, StreamWriter reportWriter)
{
    List<SortedDictionary<int, SortedDictionary<long, int>>>[] allResults
        = new List<SortedDictionary<int,SortedDictionary<long,int>>>[files.Length];
    List<SortedDictionary<int, SortedDictionary<long, int>>> results;
    Simulation_DenemePositionEstimator p;
    Simulation_WimaxStreamReader reader;
    String ret;

    for (int i = 0; i < files.Length; i++)
    {
        System.Console.WriteLine("File " + (i+1) + "/" + files.Length + " being processed.");
        reader = new Simulation_WimaxStreamReader(grids, new StreamReader(files[i]));
        p = new Simulation_DenemePositionEstimator(grids, reader);
        // Using parameters in script file which were saved into
        // different variables when Simulation instance was created.
        results = 
            p.StartInvestigation(maxRssiDiff, maxCinrDiff, maxAvgTxPwrDiff, 
                maxUncontinuity, radiusForNeighbors, expansionFactor, increment,
                n, numberOfIterations, resetCountForPositioning);
        allResults[i] = results;
        reader.Close();
    }

    ret = Statistics(allResults);
    System.Console.WriteLine(ret);
    reportWriter.WriteLine(ret);
    reportWriter.Flush();

    return ret;
}
脚本文件:

# Horizontal grid count
# Vertical grid count
# maxRssiDiff is the maximum RSSI difference allowed.
# maxCinrDiff is the maximum CINR difference allowed.
# maxAvgTxPwrDiff is the maximum AvgTxPwr difference allowed.
# maxUncontinuity
# radiusForNeighbors
# expansionFactor
# increment
# n -> MT'den gelen kaç değerin ortalaması alınıp yer bulma algoritmasına girdi olarak verilsin?
# Algoritma kaç adımda bir sonuçları dosyaya yazsın?
# Kaç adımdan sonra yer bulma işlemine sıfırdan başlamış gibi devam etsin?
# 
# Örnek:
# 118   90  4   3   4   2   1   1   1   3   10  100
118 90  6   4   6   2   1   1   1   3   250 500
# 200   140 4   3   4   2   1   1   1   3   10  100
似乎有些东西调用该方法的频率比您预期的要高

在方法的第一行放置一个断点,然后查看调用它的时间和原因。错误几乎必然出现在调用代码中,而不是方法本身,这意味着我们除了建议断点、记录堆栈跟踪等方法外帮不了什么忙。

似乎有什么东西更频繁地调用方法了一个你期待的好消息


在方法的第一行放置一个断点,然后查看调用它的时间和原因。错误几乎必然出现在调用代码中,而不是方法本身,这意味着我们除了建议断点、记录堆栈跟踪等内容外帮不了什么忙。

您在某个地方有一个borked循环。您发布的代码没有被覆盖恐怕我不想复制它……还有:你用线程做了什么有趣的事情吗?可能与狡猾的“捕获”有关?您需要添加更多详细信息,例如调用此函数的代码。可能还有处理的详细信息-处理是异步完成的吗?我不使用线程。我只是读取文件并进行一些计算。我很快就会发布代码。@Wim:我不认为有异步处理。这是一个简单的代码。我不会如果OpenFileDialog有问题。因为,我记得我选择了6个文件。但是循环使用不同的文件计数(files.Length)运行了4次。另外,调用函数调用“Start”只有在脚本文件中有多行时才能多次执行。当只有一行时,它为什么可以读取多行?您的某个地方有一个borked循环。您发布的代码恐怕不足以复制它……另外:您在线程方面做了什么有趣的事情吗?可能与狡猾的“捕获”有关?您需要添加更多详细信息,例如调用此函数的代码。可能还有处理的详细信息-处理是异步完成的吗?我不使用线程。我只是读取文件并进行一些计算。我很快就会发布代码。@Wim:我不认为有异步处理。这是一个简单的代码。我不会如果OpenFileDialog有问题。因为,我记得我选择了6个文件。但是循环使用不同的文件计数(files.Length)运行了4次。另外,调用函数调用“Start”只有在脚本文件中有多行时才可以多次读取。为什么只有一行时它可以读取多行?我照你说的做了,但问题从那时起就再也没有出现过。而且只有一个地方调用了上述函数。这让我抓狂。因此,请在该调用位置登录(带有适当的信息,可以告诉你它为什么叫它)-下次出错时,您将获得更多信息。登录是一个好主意,但我不知道如何做。我真的很困惑。我现在就尝试一下,但我必须再次等待很多小时才能看到糟糕的结果。我照您说的做了,但自那以后问题再也没有发生过。此外,只有一个地方上面的函数被调用了。它让我抓狂。所以把登录放在那个调用位置(带有适当的信息,它会告诉你为什么调用它)-下次出错时,您将获得更多信息。登录是一个好主意,但我不知道如何操作。我真的很困惑。我现在就尝试一下,但我必须等待很多小时才能看到糟糕的结果。
    // read a line from script file.
    while((line = reader.ReadLine()) != null)
    {
        // line starting with # is comment.
        if (line.StartsWith("#") == false)
        {
            // save parameters retrieved from script file into an array.
            values = line.Split(delimiters);
            // new Simulation instance with new parameters
            sim = new Simulation(map, values);
            // Start simulation. scenarioFiles comes from OpenFileDialog.
            report = sim.Start(scenarioFiles, reportWriter);
            //reportWriter.WriteLine(report);
            reportWriter.WriteLine("---------------NEW-PARAMETERS---------------");
            reportWriter.Flush();
        }
    }
# Horizontal grid count
# Vertical grid count
# maxRssiDiff is the maximum RSSI difference allowed.
# maxCinrDiff is the maximum CINR difference allowed.
# maxAvgTxPwrDiff is the maximum AvgTxPwr difference allowed.
# maxUncontinuity
# radiusForNeighbors
# expansionFactor
# increment
# n -> MT'den gelen kaç değerin ortalaması alınıp yer bulma algoritmasına girdi olarak verilsin?
# Algoritma kaç adımda bir sonuçları dosyaya yazsın?
# Kaç adımdan sonra yer bulma işlemine sıfırdan başlamış gibi devam etsin?
# 
# Örnek:
# 118   90  4   3   4   2   1   1   1   3   10  100
118 90  6   4   6   2   1   1   1   3   250 500
# 200   140 4   3   4   2   1   1   1   3   10  100