B
bytebugs
Hi,
As a matter of principle I have refranied from creating an instance of
Form or UserControl from within a class that does not inherit from
System.Windows.Form.
I am looking for comments on Pros and Cons of the approach.
My logic has been that UI is always executed on the main application
thread. I use Control.InvokeRequired or delegates to ensure that I am
always changing something on the UI in the context of the main
thread.
If I were to create an instance of form in a non-ui class (one that
does not inherit from System.Windows.Form) I am inviting potential
trouble where someone may instantiate the non-ui class on a worker
thread which in turn will instantiate a form. Now we are in a
situation that we have a form that is created on worker thread.
Please put u'r comments on this subject. Is it a hard and fast rule
that create an instance of a UI/Form object only on the main thread?
As a matter of principle I have refranied from creating an instance of
Form or UserControl from within a class that does not inherit from
System.Windows.Form.
I am looking for comments on Pros and Cons of the approach.
My logic has been that UI is always executed on the main application
thread. I use Control.InvokeRequired or delegates to ensure that I am
always changing something on the UI in the context of the main
thread.
If I were to create an instance of form in a non-ui class (one that
does not inherit from System.Windows.Form) I am inviting potential
trouble where someone may instantiate the non-ui class on a worker
thread which in turn will instantiate a form. Now we are in a
situation that we have a form that is created on worker thread.
Please put u'r comments on this subject. Is it a hard and fast rule
that create an instance of a UI/Form object only on the main thread?