I have a task - to create a label from textboxes, width TableWidth , height TableHeigth . For large values ββ(50 * 50), the plate is created for quite a long time, so I decided to do a parallel drawing along the lines. But the given code completely weighs the program. Please tell me what could be wrong? There are suggestions that a thread-safe operation is performed somewhere, but where exactly ...
Parallel.For(1, table.TableWidth + 1, x => { var i = x; for (int y = 1; y <= table.TableHeight; y++) { var j = y; TextBox textbox; if (!textBoxes.ContainsKey(new Point(i, j))) { textbox = new TextBox(); textBoxes.Add(new Point(i, j), textbox); textbox.BorderStyle = BorderStyle.Fixed3D; Controls.Add(textbox); } textbox = textBoxes[new Point(i, j)]; textbox.Location = new Point(ColumnsCoords[i], RowsCoords[j]); textbox.Width = table.ColumnsWidth[i]; textbox.Height = table.RowsHeight[j]; textbox.Text = table[i, j].Data; textbox.GotFocus += (s, a) => { focusedCellCoords.Text = new Point(i, j).ToString(); currentTextBox = textbox; focusedCell.Text = textbox.Text; }; textbox.TextChanged += (s, a) => { PushData(new Point(i, j), textbox.Text); currentTextBox = textbox; focusedCell.Text = textbox.Text; }; } });
table?textBoxescollection thread safe? Is it planned to further remove these textboxes? Events in the form of lambda will not allow to unsubscribe from them - a memory leak is possible. - Alexander PetrovDataGridViewtype? Or, for example,TableLayoutPanelfor textboxes? - Alexander Petrov