Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Speech / Src / Internal / SapiInterop / EventNotify.cs / 1 / EventNotify.cs
//------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------- using System; using System.Diagnostics; using System.Speech.Internal.SapiInterop; using System.Threading; using System.Speech.AudioFormat; using System.Collections.Generic; namespace System.Speech.Internal.SapiInterop { internal class SpNotifySink : ISpNotifySink { public SpNotifySink (EventNotify eventNotify) { _eventNotifyReference = new WeakReference (eventNotify); } void ISpNotifySink.Notify () { EventNotify eventNotify = (EventNotify) _eventNotifyReference.Target; if (eventNotify != null) { ThreadPool.QueueUserWorkItem (new WaitCallback (eventNotify.SendNotification)); } } private WeakReference _eventNotifyReference; } /// Dispatches events from ISpEventSource to DispatchEventDelegate on a thread /// compatible with the application model of the thread that created this object. internal class EventNotify { //******************************************************************* // // Constructors // //******************************************************************* #region Constructors internal EventNotify (ISpEventSource sapiEventSource, IAsyncDispatch dispatcher, bool additionalSapiFeatures) { // Remember event source _sapiEventSourceReference = new WeakReference (sapiEventSource); _dispatcher = dispatcher; _additionalSapiFeatures = additionalSapiFeatures; // Start listening to events from sapiEventSource. _notifySink = new SpNotifySink (this); sapiEventSource.SetNotifySink (_notifySink); } #endregion Constructors //******************************************************************** // // Internal Methods // //******************************************************************* #region Internal Methods // Finalizer is not required since ISpEventSource and AsyncOperation both implement appropriate finalizers. internal void Dispose () { lock (this) { // Since we are explicitly calling Dispose(), sapiEventSource (RCW) will normally be alive. // If Dispose() is called from a finalizer this may not be the case so check for null. if (_sapiEventSourceReference != null) { ISpEventSource sapiEventSource = (ISpEventSource) _sapiEventSourceReference.Target; if (sapiEventSource != null) { // Stop listening to events from sapiEventSource. sapiEventSource.SetNotifySink (null); _notifySink = null; } } _sapiEventSourceReference = null; } } internal void SendNotification (object ignored) { lock (this) { // Call dispatchEventDelegate for each SAPI event currently queued. if (_sapiEventSourceReference != null) { ISpEventSource sapiEventSource = (ISpEventSource) _sapiEventSourceReference.Target; if (sapiEventSource != null) { ListspeechEvents = new List (); SpeechEvent speechEvent; while (null != (speechEvent = SpeechEvent.TryCreateSpeechEvent (sapiEventSource, _additionalSapiFeatures, _audioFormat))) { speechEvents.Add (speechEvent); } _dispatcher.Post (speechEvents.ToArray ()); } } } } #endregion Methods //******************************************************************** // // Internal Properties // //******************************************************************** #region Internal Properties internal SpeechAudioFormatInfo AudioFormat { set { _audioFormat = value; } } #endregion Methods //******************************************************************* // // Private Methods // //******************************************************************** #region Private Methods #endregion //******************************************************************* // // Private Fields // //******************************************************************* #region Private Fields private IAsyncDispatch _dispatcher; private WeakReference _sapiEventSourceReference; private bool _additionalSapiFeatures; private SpeechAudioFormatInfo _audioFormat; private ISpNotifySink _notifySink; #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------- using System; using System.Diagnostics; using System.Speech.Internal.SapiInterop; using System.Threading; using System.Speech.AudioFormat; using System.Collections.Generic; namespace System.Speech.Internal.SapiInterop { internal class SpNotifySink : ISpNotifySink { public SpNotifySink (EventNotify eventNotify) { _eventNotifyReference = new WeakReference (eventNotify); } void ISpNotifySink.Notify () { EventNotify eventNotify = (EventNotify) _eventNotifyReference.Target; if (eventNotify != null) { ThreadPool.QueueUserWorkItem (new WaitCallback (eventNotify.SendNotification)); } } private WeakReference _eventNotifyReference; } /// Dispatches events from ISpEventSource to DispatchEventDelegate on a thread /// compatible with the application model of the thread that created this object. internal class EventNotify { //******************************************************************* // // Constructors // //******************************************************************* #region Constructors internal EventNotify (ISpEventSource sapiEventSource, IAsyncDispatch dispatcher, bool additionalSapiFeatures) { // Remember event source _sapiEventSourceReference = new WeakReference (sapiEventSource); _dispatcher = dispatcher; _additionalSapiFeatures = additionalSapiFeatures; // Start listening to events from sapiEventSource. _notifySink = new SpNotifySink (this); sapiEventSource.SetNotifySink (_notifySink); } #endregion Constructors //******************************************************************** // // Internal Methods // //******************************************************************* #region Internal Methods // Finalizer is not required since ISpEventSource and AsyncOperation both implement appropriate finalizers. internal void Dispose () { lock (this) { // Since we are explicitly calling Dispose(), sapiEventSource (RCW) will normally be alive. // If Dispose() is called from a finalizer this may not be the case so check for null. if (_sapiEventSourceReference != null) { ISpEventSource sapiEventSource = (ISpEventSource) _sapiEventSourceReference.Target; if (sapiEventSource != null) { // Stop listening to events from sapiEventSource. sapiEventSource.SetNotifySink (null); _notifySink = null; } } _sapiEventSourceReference = null; } } internal void SendNotification (object ignored) { lock (this) { // Call dispatchEventDelegate for each SAPI event currently queued. if (_sapiEventSourceReference != null) { ISpEventSource sapiEventSource = (ISpEventSource) _sapiEventSourceReference.Target; if (sapiEventSource != null) { ListspeechEvents = new List (); SpeechEvent speechEvent; while (null != (speechEvent = SpeechEvent.TryCreateSpeechEvent (sapiEventSource, _additionalSapiFeatures, _audioFormat))) { speechEvents.Add (speechEvent); } _dispatcher.Post (speechEvents.ToArray ()); } } } } #endregion Methods //******************************************************************** // // Internal Properties // //******************************************************************** #region Internal Properties internal SpeechAudioFormatInfo AudioFormat { set { _audioFormat = value; } } #endregion Methods //******************************************************************* // // Private Methods // //******************************************************************** #region Private Methods #endregion //******************************************************************* // // Private Fields // //******************************************************************* #region Private Fields private IAsyncDispatch _dispatcher; private WeakReference _sapiEventSourceReference; private bool _additionalSapiFeatures; private SpeechAudioFormatInfo _audioFormat; private ISpNotifySink _notifySink; #endregion Private Fields } } // 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
- XamlBrushSerializer.cs
- Variable.cs
- HtmlUtf8RawTextWriter.cs
- PathParser.cs
- SignatureGenerator.cs
- SvcMapFileLoader.cs
- TreeNodeCollection.cs
- CachedBitmap.cs
- DataFieldCollectionEditor.cs
- AlignmentYValidation.cs
- XmlSchemaCollection.cs
- WebBrowserHelper.cs
- DataGridAddNewRow.cs
- ParserExtension.cs
- InfocardChannelParameter.cs
- VirtualizedItemPattern.cs
- DefaultPropertiesToSend.cs
- Logging.cs
- DynamicActionMessageFilter.cs
- Vector3DCollectionConverter.cs
- DataKeyCollection.cs
- PropertyCondition.cs
- DataControlField.cs
- ConditionalAttribute.cs
- SessionStateUtil.cs
- ThreadStateException.cs
- Menu.cs
- ServiceHostingEnvironmentSection.cs
- ReadOnlyObservableCollection.cs
- NeutralResourcesLanguageAttribute.cs
- ListViewContainer.cs
- GPPOINT.cs
- ComponentCodeDomSerializer.cs
- EntityClientCacheKey.cs
- ILGen.cs
- Subtree.cs
- HtmlInputCheckBox.cs
- Context.cs
- ServiceModelEnhancedConfigurationElementCollection.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- Calendar.cs
- PngBitmapDecoder.cs
- HwndKeyboardInputProvider.cs
- ClientBase.cs
- Logging.cs
- BulletDecorator.cs
- BrowserCapabilitiesCodeGenerator.cs
- MetabaseServerConfig.cs
- PrePrepareMethodAttribute.cs
- OneToOneMappingSerializer.cs
- wgx_sdk_version.cs
- WebControlAdapter.cs
- TraceFilter.cs
- InfoCardTrace.cs
- Convert.cs
- LoginView.cs
- SafeThreadHandle.cs
- BindValidationContext.cs
- messageonlyhwndwrapper.cs
- TryExpression.cs
- ValidationResults.cs
- autovalidator.cs
- Logging.cs
- DXD.cs
- XamlTypeMapper.cs
- Exceptions.cs
- SelectedCellsChangedEventArgs.cs
- ResourceDictionaryCollection.cs
- HtmlInputRadioButton.cs
- RemoveStoryboard.cs
- XomlCompilerParameters.cs
- AttachedPropertyDescriptor.cs
- EncoderBestFitFallback.cs
- FtpCachePolicyElement.cs
- Timer.cs
- SystemColors.cs
- DataServiceRequestException.cs
- CodePageEncoding.cs
- DbBuffer.cs
- BamlRecordHelper.cs
- DataServiceHostWrapper.cs
- GeneralTransform3D.cs
- ISSmlParser.cs
- ActionMismatchAddressingException.cs
- GradientPanel.cs
- TextServicesProperty.cs
- MergeFilterQuery.cs
- DataRow.cs
- WindowsImpersonationContext.cs
- InternalCompensate.cs
- GenericRootAutomationPeer.cs
- Deserializer.cs
- MarginsConverter.cs
- IDispatchConstantAttribute.cs
- CodeMethodInvokeExpression.cs
- FilterQuery.cs
- WS2007FederationHttpBindingCollectionElement.cs
- HttpConfigurationContext.cs
- mediapermission.cs
- SqlClientFactory.cs