The example creates a Form that contains a TextBox control, a NumericUpDown control, and a ComboBox control, each validating its content, and an ErrorProvider for each control. The following code example demonstrates using the ErrorProvider class to notify the user of a data entry error. ![]() IExtenderProvider ISupportInitialize Examples Implements IExtenderProvider, ISupportInitialize Inheritance Implements IExtenderProvider Public Class ErrorProvider Interface ISupportInitialize Public Class ErrorProvider Public class ErrorProvider :, , type ErrorProvider = class ![]() In this article public ref class ErrorProvider : System::ComponentModel::Component, System::ComponentModel::IExtenderProvider public ref class ErrorProvider : System::ComponentModel::Component, System::ComponentModel::IExtenderProvider, System::ComponentModel::ISupportInitialize public class ErrorProvider :, Either force handle creation by calling the Control.Handle property, or wait until the Form.Load event to start the background process.Īn even better solution is to use the SynchronizationContext returned by rather than a control for cross-thread marshaling.Provides a user interface for indicating that a control on a form has an error associated with it. One solution is to wait until the form's handle has been created before starting the background thread. Typically, this happens only if a background thread is created in the constructor of the primary form for the application (as in Application.Run(new MainForm()), before the form has been shown or Application.Run has been called. If the control handle has not yet been created, you must wait until it has been created before calling Control.Invoke(Delegate) or Control.BeginInvoke(Delegate). You can protect against this case by also checking the value of Control.IsHandleCreated when Control.InvokeRequired returns false on a background thread. ![]() This might cause the control's handle to be created on the background thread, isolating the control on a thread without a message pump and making the application unstable. In the case where the control's handle has not yet been created, you should not simply call properties, methods, or events on the control. This means that Control.InvokeRequired can return false if Control.Invoke(Delegate) is not required (the call occurs on the same thread), or if the control was created on a different thread but the control's handle has not yet been created. If no appropriate handle can be found, the Control.InvokeRequired method returns false. If the control's handle does not yet exist, Control.InvokeRequired searches up the control's parent chain until it finds a control or form that does have a window handle. For all other method calls, you should use one of these invoke methods when calling from a different thread. Calling Control.CreateGraphics before the control's handle has been created on a background thread can cause illegal cross thread calls. ![]() In addition to the Control.InvokeRequired property, there are four methods on a control that are thread safe to call: Control.Invoke(Delegate), Control.BeginInvoke(Delegate), Control.EndInvoke(IAsyncResult) and Control.CreateGraphics if the handle for the control has already been created.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |