Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / ProcessMonitor.cs / 1 / ProcessMonitor.cs
namespace Microsoft.InfoCards { using System; using System.ComponentModel; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; internal class ProcessMonitor { static ProcessMonitor s_current = new ProcessMonitor(); Dictionarym_cache; object m_sync; private ProcessMonitor() { m_sync = new object(); m_cache = new Dictionary (); } public static Process GetProcessById( int id ) { return s_current.InnerGetProcessById( id ); } Process InnerGetProcessById( int id ) { Process process = null; lock( m_sync ) { if( !m_cache.TryGetValue( id, out process ) ) { process = Process.GetProcessById( id ); if( !process.HasExited ) { InitializeProcessObject( process ); // // add the entry to the cache. // m_cache.Add( process.Id, process ); } } } return process; } void InitializeProcessObject( Process process ) { // // This call can create a thread when setting the value to true. // process.EnableRaisingEvents = true; process.Exited += new EventHandler( Process_Exited ); } void Process_Exited( object sender, EventArgs e ) { Process process = (Process)sender; lock( m_sync ) { m_cache.Remove( process.Id ); } process.Exited -= new EventHandler( Process_Exited ); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlAttributeProperties.cs
- WebServicesDescriptionAttribute.cs
- TextProviderWrapper.cs
- DesignerCommandSet.cs
- processwaithandle.cs
- NumberFormatInfo.cs
- BounceEase.cs
- ServiceHandle.cs
- DesignerActionUIStateChangeEventArgs.cs
- XmlBaseReader.cs
- MeasureData.cs
- ResourceDescriptionAttribute.cs
- SystemWebSectionGroup.cs
- ObjectQueryExecutionPlan.cs
- PageAsyncTask.cs
- ResourcePropertyMemberCodeDomSerializer.cs
- Point3DAnimationBase.cs
- CodeStatement.cs
- ConstraintCollection.cs
- UserPreferenceChangedEventArgs.cs
- NumberSubstitution.cs
- ProcessDesigner.cs
- IISMapPath.cs
- DotExpr.cs
- ViewGenerator.cs
- NavigationProgressEventArgs.cs
- RemoteWebConfigurationHostStream.cs
- SimpleWebHandlerParser.cs
- ProxyGenerationError.cs
- TaiwanCalendar.cs
- XamlTemplateSerializer.cs
- FacetValueContainer.cs
- ToolStripMenuItemDesigner.cs
- DSASignatureDeformatter.cs
- DateTimeOffsetStorage.cs
- DependencyObjectType.cs
- TransformedBitmap.cs
- CapiSafeHandles.cs
- ConfigLoader.cs
- CodeTypeReferenceCollection.cs
- RegexInterpreter.cs
- PatternMatcher.cs
- X509ChainElement.cs
- InsufficientExecutionStackException.cs
- DbParameterCollectionHelper.cs
- NullableDecimalAverageAggregationOperator.cs
- SimpleType.cs
- OdbcReferenceCollection.cs
- WindowsGraphics2.cs
- Util.cs
- DefaultProxySection.cs
- Int64.cs
- KeyBinding.cs
- WebColorConverter.cs
- ConsumerConnectionPoint.cs
- GridViewActionList.cs
- SchemaInfo.cs
- WebRequestModuleElement.cs
- SQLChars.cs
- NativeMethods.cs
- WarningException.cs
- WebServiceEnumData.cs
- TypeSystem.cs
- LocalizableResourceBuilder.cs
- WebPartDisplayModeCollection.cs
- DesigntimeLicenseContext.cs
- HwndSubclass.cs
- InputEventArgs.cs
- AsnEncodedData.cs
- BitmapScalingModeValidation.cs
- Ref.cs
- RedirectionProxy.cs
- Themes.cs
- TokenDescriptor.cs
- QilTargetType.cs
- Reference.cs
- ClientTargetCollection.cs
- DockPatternIdentifiers.cs
- NavigationExpr.cs
- Page.cs
- Animatable.cs
- VisualBasicSettings.cs
- DiagnosticTraceSource.cs
- BasicCellRelation.cs
- HttpCookieCollection.cs
- DataSourceView.cs
- RepeaterItemEventArgs.cs
- SystemIPv4InterfaceProperties.cs
- FileSystemEnumerable.cs
- ColumnResult.cs
- DataTableMapping.cs
- NotConverter.cs
- SettingsAttributeDictionary.cs
- XsltSettings.cs
- ScriptRef.cs
- NotificationContext.cs
- StateBag.cs
- CodeSnippetStatement.cs
- RadioButtonRenderer.cs
- DetailsViewModeEventArgs.cs