In the Solve function of my static SudokuSolver class, I pass a Grid object which is basically just a 2d array, one spot for each cell in the sudoku puzzle. When this Grid object changes, it fires an event telling me that one of the numbers changed. In the event handler, I update the form. This all works great.
But this makes the changes go by at light speed and I want to slow it down. So, obviously you can't put in a Thread.Sleep call in the event handler because that would stop the form from responding. And even while the Grid is changing at full speed, the form is still not responding to my clicks because it is stuck processing the answer to the problem.
How do I split the time between processing the solution and still keep the form responsive?
Is putting the processing on a separate thread the only way? And if so, how do I update the form from another thread?
Indexer in Grid class which fires the OnGridItemChanged event.
public int this[int row,int col]
{
get
{
return grid[row, col];
}
set
{
if (value != grid[row, col])
{
grid[row, col] = value;
OnGridItemChanged(new GridItemChangedEventArgs(row, col));
}
}
}
Event handler attached to GridItemChanged event. This is in the MainForm class.
private void grid_GridItemChanged(object sender, GridItemChangedEventArgs e)
{
if (grid[e.Row, e.Col] == 0)
textboxGrid[e.Row, e.Col].Text = "";
else
textboxGrid[e.Row, e.Col].Text = grid[e.Row, e.Col].ToString();
this.Update();
}

New Topic/Question
Reply




MultiQuote





|