Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- DiscreteKeyFrames.cs
- TargetPerspective.cs
- TTSVoice.cs
- HttpCookiesSection.cs
- CmsUtils.cs
- DataObjectCopyingEventArgs.cs
- AsymmetricSignatureDeformatter.cs
- ObjectParameterCollection.cs
- TextTreeDeleteContentUndoUnit.cs
- HttpsChannelListener.cs
- SourceElementsCollection.cs
- FontNamesConverter.cs
- GeometryDrawing.cs
- BlockUIContainer.cs
- BindableTemplateBuilder.cs
- NetSectionGroup.cs
- DataServicePagingProviderWrapper.cs
- x509utils.cs
- Type.cs
- ClientSideQueueItem.cs
- SafeEventLogWriteHandle.cs
- XmlNotation.cs
- SafeNativeMethods.cs
- CollectionViewGroupRoot.cs
- PlainXmlWriter.cs
- NumericUpDownAccelerationCollection.cs
- WindowsIdentity.cs
- FontConverter.cs
- SEHException.cs
- ObjectParameterCollection.cs
- HitTestWithPointDrawingContextWalker.cs
- CodeRegionDirective.cs
- SqlTypeSystemProvider.cs
- MessagePropertyVariants.cs
- Setter.cs
- MsmqOutputMessage.cs
- SymbolEqualComparer.cs
- ToolStripMenuItem.cs
- DeploymentSection.cs
- Random.cs
- _ContextAwareResult.cs
- OdbcDataReader.cs
- ReadOnlyDataSource.cs
- StorageBasedPackageProperties.cs
- FlowDocumentPage.cs
- oledbconnectionstring.cs
- HtmlInputImage.cs
- FloaterBaseParagraph.cs
- AppDomainInstanceProvider.cs
- ByteStream.cs
- XmlDataDocument.cs
- PrintDialog.cs
- HtmlFormParameterReader.cs
- TCPListener.cs
- DLinqDataModelProvider.cs
- LinkClickEvent.cs
- DataTemplateSelector.cs
- XmlQueryOutput.cs
- UserPreferenceChangingEventArgs.cs
- HostingEnvironmentException.cs
- TypeListConverter.cs
- _HelperAsyncResults.cs
- SqlNodeAnnotation.cs
- SchemaComplexType.cs
- FontUnit.cs
- VScrollProperties.cs
- DataGridViewCellEventArgs.cs
- AsyncResult.cs
- BufferBuilder.cs
- XmlComment.cs
- XPathSelectionIterator.cs
- SrgsSemanticInterpretationTag.cs
- SocketInformation.cs
- SelfIssuedSamlTokenFactory.cs
- XmlNode.cs
- PeerPresenceInfo.cs
- XPathSingletonIterator.cs
- UnescapedXmlDiagnosticData.cs
- StorageMappingItemLoader.cs
- AttachedPropertyMethodSelector.cs
- XslCompiledTransform.cs
- InternalConfigHost.cs
- CmsInterop.cs
- BaseTemplateBuildProvider.cs
- ObjectHandle.cs
- DelimitedListTraceListener.cs
- ObjectMemberMapping.cs
- DisplayInformation.cs
- XPathDocumentBuilder.cs
- SecurityRuntime.cs
- CompositeScriptReferenceEventArgs.cs
- ObsoleteAttribute.cs
- ControlCachePolicy.cs
- TextDecorationUnitValidation.cs
- CmsUtils.cs
- diagnosticsswitches.cs
- InstalledFontCollection.cs
- PolyLineSegmentFigureLogic.cs
- NumberFunctions.cs
- ColorContext.cs