Splitting UI thread to view details with WinForms

Our wizard / part view of the application uses the datagridview as the wizard and the custom control as the part view. The detail view takes a long time to compute and render, making it difficult to download slowly up / down the main view.

Therefore, we would like the detail view to run asynchronously (on a separate UI thread) with change notifications from the presenter.

Creating a form in a separate thread is relatively easy since Application.Run takes a form parameter.

Is there a way to run a winforms element on a separate thread? I know that native windows on different threads can have parent / child relationships, just not sure how to set this up using winforms.

TIA,

+2


source to share


4 answers


Updating the UI from the secondary thread
http://msdn.microsoft.com/en-us/magazine/cc188732.aspx



Intuitively, you should also be able to accomplish the same thing using the BackgroundWorker. BackgroundWorker is designed to update user interface elements such as progress bars when a material is running in the background and can be canceled while it is running.

+2


source


Is the slowdown caused by loading data or is it a combination of the UI itself?



In most cases, this is the first, so if this is the case, then the logic that does the loading of the data must be abstracted into another thread. The UI code can live on the main thread as updates are fast. In this situation, you can use either Thread

or BackgroundWorker

. The key is to separate the data loading from your GUI population.

+2


source


If you turn off verbosity refreshing in code, you can significantly improve usability by sleeping 500ms between the time the user selects the master record and the time you refresh the verbose view.

This gives the user 1/2 second to scroll to the next entry without updating the view of the details at all.

+1


source


If you are taking a snapshot of speed while rendering, you should consider pausing the layout until the form has finished updating, then refresh the visible display once at the end.

this.SuspendLayout();

// Do control stuff here

this.ResumeLayout();

      

If that doesn't work, try the following:

[DllImport("user32.dll")]

public static extern bool LockWindowUpdate(IntPtr hWndLock);
//
LockWindowUpdate(this.Handle);

// Do control stuff here

this.Refresh(); //Forces a synchronous redraw of all controls

LockWindowUpdate(IntPtr.Zero);

      

http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/8a5e5188-2985-4baf-9a0e-b72064ce5aeb

+1


source







All Articles