public MainForm() { InitializeComponent(); // Set up the threading value. _uiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); _synchronizationContext = SynchronizationContext.Current; }
Action _wait = () => { System.Threading.Thread.Sleep(10); };
private void UpdateLog(string _element, string _text, int _level) { Action _updateLog = () => { logFlexGrid.Redraw = false; // Add a new row for this node. int _rowCnt = logFlexGrid.Rows.Count; logFlexGrid.Rows.Add(); if (_level == 1) { logFlexGrid.Rows[_rowCnt].IsNode = true; logFlexGrid.Rows[_rowCnt].Node.Level = _flexGridLevel; _flexGridLevel++; } else if (_level == -1) _flexGridLevel--; logFlexGrid[_rowCnt, 0] = _element; logFlexGrid[_rowCnt, 1] = DateTime.Now.TimeOfDay; logFlexGrid[_rowCnt, 2] = _text; // Perform simple status update. UpdateStatusStrip(_text); // System.Windows.Forms.Application.DoEvents(); logFlexGrid.Redraw = true; logFlexGrid.ShowCell(_rowCnt, 0); }; Task _t = Task.Factory.StartNew(_wait, TaskCreationOptions.AttachedToParent).ContinueWith(delegate { _synchronizationContext.Post(delegate { _updateLog(); }, _uiScheduler); }, TaskContinuationOptions.AttachedToParent); _t.Wait(); System.Windows.Forms.Application.DoEvents(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)