Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / WinForms / Managed / System / WinForms / ApplicationContext.cs / 1 / ApplicationContext.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms { using System; using System.Diagnostics; using System.ComponentModel; ////// /// ApplicationContext provides contextual information about an application /// thread. Specifically this allows an application author to redifine what /// circurmstances cause a message loop to exit. By default the application /// context listens to the close event on the mainForm, then exits the /// thread's message loop. /// public class ApplicationContext : IDisposable { Form mainForm; object userData; ////// /// Creates a new ApplicationContext with no mainForm. /// public ApplicationContext() : this(null) { } ////// /// Creates a new ApplicationContext with the specified mainForm. /// If OnMainFormClosed is not overriden, the thread's message /// loop will be terminated when mainForm is closed. /// public ApplicationContext(Form mainForm) { this.MainForm = mainForm; } ///~ApplicationContext() { Dispose(false); } /// /// /// Determines the mainForm for this context. This may be changed /// at anytime. /// If OnMainFormClosed is not overriden, the thread's message /// loop will be terminated when mainForm is closed. /// public Form MainForm { get { return mainForm; } set { EventHandler onClose = new EventHandler(OnMainFormDestroy); if (mainForm != null) { mainForm.HandleDestroyed -= onClose; } mainForm = value; if (mainForm != null) { mainForm.HandleDestroyed += onClose; } } } ///[ SRCategory(SR.CatData), Localizable(false), Bindable(true), SRDescription(SR.ControlTagDescr), DefaultValue(null), TypeConverter(typeof(StringConverter)), ] public object Tag { get { return userData; } set { userData = value; } } /// /// /// Is raised when the thread's message loop should be terminated. /// This is raised by calling ExitThread. /// public event EventHandler ThreadExit; ////// /// Disposes the context. This should dispose the mainForm. This is /// called immediately after the thread's message loop is terminated. /// Application will dispose all forms on this thread by default. /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } ///protected virtual void Dispose(bool disposing) { if (disposing) { if (mainForm != null) { if (!mainForm.IsDisposed) { mainForm.Dispose(); } mainForm = null; } } } /// /// /// Causes the thread's message loop to be terminated. This /// will call ExitThreadCore. /// public void ExitThread() { ExitThreadCore(); } ////// /// Causes the thread's message loop to be terminated. /// protected virtual void ExitThreadCore() { if (ThreadExit != null) { ThreadExit(this, EventArgs.Empty); } } ////// /// Called when the mainForm is closed. The default implementation /// of this will call ExitThreadCore. /// protected virtual void OnMainFormClosed(object sender, EventArgs e) { ExitThreadCore(); } ////// Called when the mainForm is closed. The default implementation /// of this will call ExitThreadCore. /// private void OnMainFormDestroy(object sender, EventArgs e) { Form form = (Form)sender; if (!form.RecreatingHandle) { form.HandleDestroyed -= new EventHandler(OnMainFormDestroy); OnMainFormClosed(sender, e); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms { using System; using System.Diagnostics; using System.ComponentModel; ////// /// ApplicationContext provides contextual information about an application /// thread. Specifically this allows an application author to redifine what /// circurmstances cause a message loop to exit. By default the application /// context listens to the close event on the mainForm, then exits the /// thread's message loop. /// public class ApplicationContext : IDisposable { Form mainForm; object userData; ////// /// Creates a new ApplicationContext with no mainForm. /// public ApplicationContext() : this(null) { } ////// /// Creates a new ApplicationContext with the specified mainForm. /// If OnMainFormClosed is not overriden, the thread's message /// loop will be terminated when mainForm is closed. /// public ApplicationContext(Form mainForm) { this.MainForm = mainForm; } ///~ApplicationContext() { Dispose(false); } /// /// /// Determines the mainForm for this context. This may be changed /// at anytime. /// If OnMainFormClosed is not overriden, the thread's message /// loop will be terminated when mainForm is closed. /// public Form MainForm { get { return mainForm; } set { EventHandler onClose = new EventHandler(OnMainFormDestroy); if (mainForm != null) { mainForm.HandleDestroyed -= onClose; } mainForm = value; if (mainForm != null) { mainForm.HandleDestroyed += onClose; } } } ///[ SRCategory(SR.CatData), Localizable(false), Bindable(true), SRDescription(SR.ControlTagDescr), DefaultValue(null), TypeConverter(typeof(StringConverter)), ] public object Tag { get { return userData; } set { userData = value; } } /// /// /// Is raised when the thread's message loop should be terminated. /// This is raised by calling ExitThread. /// public event EventHandler ThreadExit; ////// /// Disposes the context. This should dispose the mainForm. This is /// called immediately after the thread's message loop is terminated. /// Application will dispose all forms on this thread by default. /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } ///protected virtual void Dispose(bool disposing) { if (disposing) { if (mainForm != null) { if (!mainForm.IsDisposed) { mainForm.Dispose(); } mainForm = null; } } } /// /// /// Causes the thread's message loop to be terminated. This /// will call ExitThreadCore. /// public void ExitThread() { ExitThreadCore(); } ////// /// Causes the thread's message loop to be terminated. /// protected virtual void ExitThreadCore() { if (ThreadExit != null) { ThreadExit(this, EventArgs.Empty); } } ////// /// Called when the mainForm is closed. The default implementation /// of this will call ExitThreadCore. /// protected virtual void OnMainFormClosed(object sender, EventArgs e) { ExitThreadCore(); } ////// Called when the mainForm is closed. The default implementation /// of this will call ExitThreadCore. /// private void OnMainFormDestroy(object sender, EventArgs e) { Form form = (Form)sender; if (!form.RecreatingHandle) { form.HandleDestroyed -= new EventHandler(OnMainFormDestroy); OnMainFormClosed(sender, e); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- URL.cs
- NumberSubstitution.cs
- RegistryPermission.cs
- GrowingArray.cs
- FeatureSupport.cs
- DesignerCalendarAdapter.cs
- PageRanges.cs
- CodePageEncoding.cs
- NativeMethods.cs
- DataObject.cs
- EntityDescriptor.cs
- SuspendDesigner.cs
- OutputCacheProfile.cs
- SamlAuthorizationDecisionClaimResource.cs
- SerializerProvider.cs
- EntityDataSourceDesignerHelper.cs
- DataGridViewRowsAddedEventArgs.cs
- QuaternionKeyFrameCollection.cs
- TableStyle.cs
- DetailsViewInsertedEventArgs.cs
- TextFindEngine.cs
- DbConnectionPoolCounters.cs
- ConfigXmlElement.cs
- CodePropertyReferenceExpression.cs
- SQLCharsStorage.cs
- WrappedIUnknown.cs
- CategoryNameCollection.cs
- MdImport.cs
- SoapCommonClasses.cs
- HtmlImage.cs
- HostingEnvironmentSection.cs
- TransformDescriptor.cs
- PathData.cs
- RegistryKey.cs
- ForceCopyBuildProvider.cs
- ContentElementAutomationPeer.cs
- NullableLongAverageAggregationOperator.cs
- PageRanges.cs
- TriState.cs
- Validator.cs
- OleDbCommand.cs
- ResourcePermissionBaseEntry.cs
- PreviewPageInfo.cs
- ImageListStreamer.cs
- CodeMemberField.cs
- DesignConnectionCollection.cs
- ProcessInfo.cs
- PrinterResolution.cs
- ControlUtil.cs
- xmlsaver.cs
- Serializer.cs
- MultiBindingExpression.cs
- PassportAuthenticationModule.cs
- MemberHolder.cs
- GZipUtils.cs
- Point3DConverter.cs
- parserscommon.cs
- DetailsViewCommandEventArgs.cs
- Matrix3DValueSerializer.cs
- OracleTimeSpan.cs
- ZipIOLocalFileHeader.cs
- TextEffectResolver.cs
- ViewPort3D.cs
- CryptographicAttribute.cs
- SqlBulkCopyColumnMapping.cs
- OnOperation.cs
- DataObjectEventArgs.cs
- UidManager.cs
- MsmqElementBase.cs
- GCHandleCookieTable.cs
- DateTimeUtil.cs
- StringInfo.cs
- DoubleStorage.cs
- ToolStripDropDown.cs
- PersonalizationStateQuery.cs
- ListViewGroupConverter.cs
- BaseUriWithWildcard.cs
- DocumentEventArgs.cs
- FunctionImportElement.cs
- RadioButtonPopupAdapter.cs
- ReflectPropertyDescriptor.cs
- Sentence.cs
- InvokeWebServiceDesigner.cs
- SharedUtils.cs
- StoreContentChangedEventArgs.cs
- GB18030Encoding.cs
- BitmapFrame.cs
- InvokePatternIdentifiers.cs
- HttpCookiesSection.cs
- IncrementalReadDecoders.cs
- StrokeCollection2.cs
- SqlNamer.cs
- SecurityIdentifierConverter.cs
- AssemblyInfo.cs
- Form.cs
- GlyphCache.cs
- InvalidAsynchronousStateException.cs
- HttpSessionStateBase.cs
- UInt64.cs
- XmlAnyAttributeAttribute.cs