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
- ParserStreamGeometryContext.cs
- MultipleViewPattern.cs
- SqlWorkflowPersistenceService.cs
- XmlSchemaObject.cs
- Graphics.cs
- TransformPatternIdentifiers.cs
- Binding.cs
- TransactionTable.cs
- FocusTracker.cs
- RecognizerStateChangedEventArgs.cs
- HScrollBar.cs
- PageAsyncTaskManager.cs
- StructuralCache.cs
- AuthStoreRoleProvider.cs
- TextClipboardData.cs
- Pkcs7Signer.cs
- TraceSwitch.cs
- IfJoinedCondition.cs
- BitHelper.cs
- DefaultTextStore.cs
- ResizeGrip.cs
- HtmlButton.cs
- CodePropertyReferenceExpression.cs
- TextTreeTextElementNode.cs
- ServicePointManager.cs
- WebPartEditorOkVerb.cs
- SqlXml.cs
- RemotingService.cs
- OleDbEnumerator.cs
- NonBatchDirectoryCompiler.cs
- ProgressBar.cs
- PerfCounterSection.cs
- ChtmlCommandAdapter.cs
- AbsoluteQuery.cs
- NotSupportedException.cs
- TreeViewImageGenerator.cs
- BitmapEffectState.cs
- CalendarDataBindingHandler.cs
- ProcessRequestAsyncResult.cs
- ContextDataSource.cs
- FixedSOMTableCell.cs
- Documentation.cs
- WebPartRestoreVerb.cs
- PreProcessInputEventArgs.cs
- SecUtil.cs
- behaviorssection.cs
- AsymmetricSignatureDeformatter.cs
- ConfigurationManagerInternalFactory.cs
- mediapermission.cs
- AccessDataSource.cs
- EventManager.cs
- XmlUtilWriter.cs
- PropertyGeneratedEventArgs.cs
- SqlDataSourceFilteringEventArgs.cs
- cryptoapiTransform.cs
- LineGeometry.cs
- XmlSchemaParticle.cs
- WeakReferenceEnumerator.cs
- OutputChannel.cs
- TextSpan.cs
- Label.cs
- ColumnResizeUndoUnit.cs
- XmlSubtreeReader.cs
- WebSysDescriptionAttribute.cs
- DynamicEntity.cs
- ErrorRuntimeConfig.cs
- XmlDataDocument.cs
- XsdDataContractImporter.cs
- DataGridViewCellStyleConverter.cs
- FileVersion.cs
- VersionedStream.cs
- InvalidWMPVersionException.cs
- EditorZoneDesigner.cs
- ObfuscateAssemblyAttribute.cs
- LoadMessageLogger.cs
- InlineObject.cs
- X509IssuerSerialKeyIdentifierClause.cs
- BitFlagsGenerator.cs
- PropertyGridCommands.cs
- PrintingPermission.cs
- MoveSizeWinEventHandler.cs
- DataControlCommands.cs
- SqlDataSourceConfigureFilterForm.cs
- ItemChangedEventArgs.cs
- DataGridView.cs
- TextEffectCollection.cs
- PermissionSetEnumerator.cs
- RectangleConverter.cs
- _TimerThread.cs
- TextParaLineResult.cs
- XmlSchemaAnyAttribute.cs
- SoundPlayerAction.cs
- CompilerInfo.cs
- DataGridViewButtonCell.cs
- TextCompositionManager.cs
- AtlasWeb.Designer.cs
- OleDbRowUpdatingEvent.cs
- SByteConverter.cs
- TransactedReceiveData.cs
- PropertyPath.cs