Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / 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
- ThaiBuddhistCalendar.cs
- DynamicValueConverter.cs
- MailDefinition.cs
- PeerInputChannelListener.cs
- TextEndOfLine.cs
- RuntimeConfig.cs
- MSAAWinEventWrap.cs
- MatrixCamera.cs
- EntitySetDataBindingList.cs
- ControlAdapter.cs
- DataSourceCacheDurationConverter.cs
- Positioning.cs
- selecteditemcollection.cs
- OletxVolatileEnlistment.cs
- PixelShader.cs
- Parameter.cs
- StrokeCollection2.cs
- SystemIPInterfaceProperties.cs
- BaseProcessor.cs
- WindowsRichEditRange.cs
- TypeConverters.cs
- Literal.cs
- AutomationFocusChangedEventArgs.cs
- DescendantQuery.cs
- RequestChannel.cs
- CanonicalFormWriter.cs
- GeometryHitTestResult.cs
- RegexMatch.cs
- ProvidersHelper.cs
- ReceiveCompletedEventArgs.cs
- ComboBoxDesigner.cs
- GrammarBuilderPhrase.cs
- MostlySingletonList.cs
- Select.cs
- SelectorItemAutomationPeer.cs
- _SslSessionsCache.cs
- EditableRegion.cs
- InfoCardPolicy.cs
- PassportAuthenticationEventArgs.cs
- PerfCounterSection.cs
- DataContractJsonSerializer.cs
- EditingMode.cs
- PropertyNames.cs
- MimeTypeMapper.cs
- BeginStoryboard.cs
- SecUtil.cs
- BamlRecords.cs
- TimeSpan.cs
- ProcessInputEventArgs.cs
- UInt32Converter.cs
- FixedSOMPageElement.cs
- OutOfProcStateClientManager.cs
- NativeMethods.cs
- HMACMD5.cs
- PropertyRecord.cs
- Permission.cs
- QilValidationVisitor.cs
- webclient.cs
- FileUtil.cs
- GradientBrush.cs
- _DisconnectOverlappedAsyncResult.cs
- BamlResourceSerializer.cs
- DES.cs
- FontSourceCollection.cs
- TemplateBindingExtensionConverter.cs
- QilPatternVisitor.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- GradientStop.cs
- CompareInfo.cs
- ValidationException.cs
- FixedSchema.cs
- PackageDigitalSignatureManager.cs
- EnvelopedPkcs7.cs
- SimplePropertyEntry.cs
- UnsafePeerToPeerMethods.cs
- BindingListCollectionView.cs
- SchemaElementLookUpTable.cs
- DetailsViewCommandEventArgs.cs
- ShellProvider.cs
- EndOfStreamException.cs
- Misc.cs
- _SecureChannel.cs
- URLMembershipCondition.cs
- TerminateWorkflow.cs
- Misc.cs
- ReturnEventArgs.cs
- ImmutableAssemblyCacheEntry.cs
- SynchronizedInputAdaptor.cs
- InstanceLockQueryResult.cs
- TargetControlTypeAttribute.cs
- XmlQualifiedNameTest.cs
- SessionPageStatePersister.cs
- RemoteCryptoRsaServiceProvider.cs
- odbcmetadatacolumnnames.cs
- HttpCachePolicyElement.cs
- ArgIterator.cs
- XmlComplianceUtil.cs
- DesignerAttribute.cs
- webbrowsersite.cs
- FormatConvertedBitmap.cs