Code:
/ DotNET / DotNET / 8.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Control.cs
- FixedDocument.cs
- CachingHintValidation.cs
- PropertyManager.cs
- CallSiteOps.cs
- CodeLinePragma.cs
- QuaternionValueSerializer.cs
- TemplateApplicationHelper.cs
- DocumentApplicationJournalEntry.cs
- VectorAnimationBase.cs
- Activity.cs
- CellIdBoolean.cs
- Utils.cs
- ProviderSettingsCollection.cs
- ControllableStoryboardAction.cs
- ClientSettingsStore.cs
- counter.cs
- Setter.cs
- GridViewEditEventArgs.cs
- JapaneseLunisolarCalendar.cs
- Exceptions.cs
- webclient.cs
- SafeNativeMemoryHandle.cs
- OutputCacheSettingsSection.cs
- SiteOfOriginContainer.cs
- ValueSerializer.cs
- X509CertificateChain.cs
- DelayDesigner.cs
- Token.cs
- SafeLibraryHandle.cs
- InputLangChangeEvent.cs
- ThicknessAnimation.cs
- UIElementIsland.cs
- TextDocumentView.cs
- _BasicClient.cs
- Context.cs
- GenericWebPart.cs
- LayoutUtils.cs
- SqlRemoveConstantOrderBy.cs
- RawUIStateInputReport.cs
- IIS7UserPrincipal.cs
- CompilerGeneratedAttribute.cs
- HttpRuntime.cs
- Context.cs
- XhtmlBasicCalendarAdapter.cs
- NativeRecognizer.cs
- TextParaClient.cs
- EmptyImpersonationContext.cs
- XmlName.cs
- PageHandlerFactory.cs
- ExtenderProvidedPropertyAttribute.cs
- OleDbMetaDataFactory.cs
- Random.cs
- XmlWrappingReader.cs
- NativeMethods.cs
- ScanQueryOperator.cs
- X509ChainPolicy.cs
- ScriptManagerProxy.cs
- DataPagerCommandEventArgs.cs
- XsltInput.cs
- Int32AnimationUsingKeyFrames.cs
- SystemColors.cs
- PostBackOptions.cs
- ResourceDictionary.cs
- controlskin.cs
- PageAsyncTaskManager.cs
- PeerValidationBehavior.cs
- MatchingStyle.cs
- DataServicePagingProviderWrapper.cs
- UserMapPath.cs
- ContentControl.cs
- BaseDataList.cs
- AQNBuilder.cs
- FixedPageAutomationPeer.cs
- RtfControlWordInfo.cs
- UntypedNullExpression.cs
- ToolStripPanelRenderEventArgs.cs
- StreamResourceInfo.cs
- TimeSpanValidator.cs
- DrawListViewColumnHeaderEventArgs.cs
- MergeFilterQuery.cs
- SqlParameterizer.cs
- WebBrowserDesigner.cs
- BindingUtils.cs
- CaseInsensitiveOrdinalStringComparer.cs
- ClientFormsAuthenticationCredentials.cs
- BaseProcessor.cs
- SrgsDocument.cs
- DuplicateWaitObjectException.cs
- SQLDouble.cs
- EventMap.cs
- ParentUndoUnit.cs
- MemberPath.cs
- DataGridCellsPanel.cs
- ProxyWebPartConnectionCollection.cs
- CapabilitiesRule.cs
- SecurityChannelListener.cs
- TextBoxLine.cs
- HTMLTextWriter.cs
- FacetDescriptionElement.cs