Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / ApplicationContext.cs / 1305376 / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataBindingsDialog.cs
- LinkUtilities.cs
- SHA1CryptoServiceProvider.cs
- ServiceMetadataBehavior.cs
- Scene3D.cs
- PackageFilter.cs
- SplitContainer.cs
- GlyphRunDrawing.cs
- URI.cs
- CellParaClient.cs
- XmlSchemaAnyAttribute.cs
- ADMembershipUser.cs
- _TransmitFileOverlappedAsyncResult.cs
- StrongNameKeyPair.cs
- RectAnimationBase.cs
- HandleRef.cs
- HttpAsyncResult.cs
- ImageSourceConverter.cs
- FormViewModeEventArgs.cs
- InternalConfigHost.cs
- Message.cs
- DataControlFieldCollection.cs
- XmlRawWriterWrapper.cs
- KernelTypeValidation.cs
- PeerNameRegistration.cs
- ParameterEditorUserControl.cs
- EndpointInfo.cs
- SchemaSetCompiler.cs
- NativeMethods.cs
- CheckBoxField.cs
- NumericExpr.cs
- OwnerDrawPropertyBag.cs
- PackageDigitalSignatureManager.cs
- ClientEventManager.cs
- NestPullup.cs
- OlePropertyStructs.cs
- LightweightCodeGenerator.cs
- BitVec.cs
- FontUnit.cs
- TextSelectionHighlightLayer.cs
- RuleSetDialog.cs
- AuthenticateEventArgs.cs
- XamlRtfConverter.cs
- URLAttribute.cs
- DrawingContextWalker.cs
- ComplexPropertyEntry.cs
- DataGridLinkButton.cs
- MenuItemCollectionEditorDialog.cs
- MessageQueueInstaller.cs
- SafeLibraryHandle.cs
- MetadataArtifactLoaderResource.cs
- EmptyQuery.cs
- IISMapPath.cs
- UIPermission.cs
- GroupQuery.cs
- SafeFileMapViewHandle.cs
- XmlSchemaSimpleContent.cs
- LocalizationParserHooks.cs
- Window.cs
- SudsCommon.cs
- QuaternionAnimation.cs
- PropertyEntry.cs
- Vector3DValueSerializer.cs
- EntityDesignerDataSourceView.cs
- SignatureToken.cs
- TextComposition.cs
- PageThemeCodeDomTreeGenerator.cs
- CompositionDesigner.cs
- EntityDataSourceWizardForm.cs
- SqlDependency.cs
- URLBuilder.cs
- precedingquery.cs
- XPathSelectionIterator.cs
- CollectionCodeDomSerializer.cs
- TiffBitmapDecoder.cs
- ClientSponsor.cs
- CompoundFileIOPermission.cs
- FilteredXmlReader.cs
- UnauthorizedWebPart.cs
- Group.cs
- NullableFloatSumAggregationOperator.cs
- ServiceParser.cs
- EventManager.cs
- InputEventArgs.cs
- LinqDataSourceView.cs
- CompensateDesigner.cs
- ChtmlPhoneCallAdapter.cs
- Condition.cs
- ResourceDisplayNameAttribute.cs
- EventEntry.cs
- FontStretches.cs
- ColorInterpolationModeValidation.cs
- AstNode.cs
- ImageMapEventArgs.cs
- FaultDescriptionCollection.cs
- DirtyTextRange.cs
- StringReader.cs
- GB18030Encoding.cs
- Content.cs
- GridViewRowPresenterBase.cs