Bonjour,
J"utilise l'action asynchrone pour convertir les dates dans mon datatable. Elle fonctionne pour des données d'environ 1000 lignes mais j'obtiens des erreurs quand je travailles sur une grosse données 50000 lignes.

ArgumentOutOfRangeException
{"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
private DataTable convertAODateTime(DataTable excelData, List<ColumnInfo> colInfo)
        {
            for (int i = 0; i < colInfo.Count; i++)
            {
                if (colInfo[i].type.Equals("DateTime"))
                {
                    int firstPart = excelData.Rows.Count / 2;
                    Action firstAction = delegate
                    {
                        for (int j = 0; j < firstPart; j++)
                        {
                            excelData.Rows[j][i] = convert(excelData.Rows[j][i].ToString());
                        }
                    };
                    Action secondAction = delegate
                    {
                        for (int k = firstPart; k < excelData.Rows.Count; k++)
                        {
                            excelData.Rows[k][i] = convert(excelData.Rows[k][i].ToString());
                        }
                    };
 
                    IAsyncResult firstHandle = firstAction.BeginInvoke(null, null);
                    IAsyncResult secondHandle = secondAction.BeginInvoke(null, null);
 
                    firstAction.EndInvoke(firstHandle);
                    secondAction.EndInvoke(secondHandle);
                }
            }
            return excelData;
        }
 
        private string convert(string data)
        {
            double value;
            if (double.TryParse(data, out value))
            {
                try
                {
                    data= DateTime.FromOADate(value).ToString();
                }
                catch
                {                    
                }
            }
 
            return data;
        }
Qu'est ce qui peut provoquer cette erreur? Est ce la synchronisation lors de la lecture ou l'ecriture dans le datatable?
merci pour votre aide