Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / System / Windows / Input / Stylus / PenThreadPool.cs / 1305600 / PenThreadPool.cs
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Threading;
using System.Security;
using System.Security.Permissions;
using MS.Win32.Penimc;
namespace System.Windows.Input
{
/////////////////////////////////////////////////////////////////////////
///
///
///
internal class PenThreadPool
{
///
/// Critical - Constructor for singleton of our PenThreadPool.
/// marking this critical to prevent inadvertant access by transparent code
///
/// Called by critical methods:
/// Instance (above)
///
///
[SecurityCritical]
static PenThreadPool()
{
}
/////////////////////////////////////////////////////////////////////
///
///
///
///
/// Critical - marking this critical to prevent inadvertant
/// access by transparent code
///
///
[SecurityCritical]
[ThreadStatic]
private static PenThreadPool _penThreadPool;
/////////////////////////////////////////////////////////////////////
///
///
///
/// Critical - Returns a PenThread (creates as needed).
/// marking this critical to prevent inadvertant access by transparent code
///
/// Called by critical methods:
/// PenContext.Dispose
/// PenContext.Enable
/// PenContext.Disable
///
///
[SecurityCritical]
internal static PenThread GetPenThreadForPenContext(PenContext penContext)
{
// Create the threadstatic DynamicRendererThreadManager as needed for calling thread.
// It only creates one
if (_penThreadPool == null)
{
_penThreadPool = new PenThreadPool();
}
return _penThreadPool.GetPenThreadForPenContextHelper(penContext); // Adds to weak ref list if creating new one.
}
/////////////////////////////////////////////////////////////////////
///
///
///
///
/// Critical - marking this critical to prevent inadvertant
/// access by transparent code
///
///
[SecurityCritical]
private List _penThreadWeakRefList;
/////////////////////////////////////////////////////////////////////
///
///
///
///
/// Critical - Initializes critical data: m_PenThreads
///
///
[SecurityCritical]
internal PenThreadPool()
{
_penThreadWeakRefList = new List();
}
///
/// Critical - Calls SecurityCritical code (PenThread constructor).
/// Called by BeginService.
/// TreatAsSafe boundry is Stylus.EnableCore, Stylus.RegisterHwndForInput
/// and HwndWrapperHook class (via HwndSource.InputFilterMessage).
///
[SecurityCritical]
private PenThread GetPenThreadForPenContextHelper(PenContext penContext)
{
bool needCleanup = false;
PenThread penThread = null;
int i;
// Scan existing penthreads to see if we have an available slot for context.
for (i=0; i < _penThreadWeakRefList.Count; i++)
{
PenThread penThreadFound = _penThreadWeakRefList[i].Target as PenThread;
if (penThreadFound == null)
{
needCleanup = true;
}
else
{
// See if we can use this one
if (penContext == null || penThreadFound.AddPenContext(penContext))
{
// We can use this one.
penThread = penThreadFound;
break;
}
}
}
if (needCleanup)
{
// prune invalid refs
for (i=_penThreadWeakRefList.Count - 1; i >= 0; i--)
{
if (_penThreadWeakRefList[i].Target == null)
{
_penThreadWeakRefList.RemoveAt(i);
}
}
}
if (penThread == null)
{
penThread = new PenThread();
// Make sure we add this context to the penthread
if (penContext != null)
{
penThread.AddPenContext(penContext);
}
_penThreadWeakRefList.Add(new WeakReference(penThread));
}
return penThread;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Threading;
using System.Security;
using System.Security.Permissions;
using MS.Win32.Penimc;
namespace System.Windows.Input
{
/////////////////////////////////////////////////////////////////////////
///
///
///
internal class PenThreadPool
{
///
/// Critical - Constructor for singleton of our PenThreadPool.
/// marking this critical to prevent inadvertant access by transparent code
///
/// Called by critical methods:
/// Instance (above)
///
///
[SecurityCritical]
static PenThreadPool()
{
}
/////////////////////////////////////////////////////////////////////
///
///
///
///
/// Critical - marking this critical to prevent inadvertant
/// access by transparent code
///
///
[SecurityCritical]
[ThreadStatic]
private static PenThreadPool _penThreadPool;
/////////////////////////////////////////////////////////////////////
///
///
///
/// Critical - Returns a PenThread (creates as needed).
/// marking this critical to prevent inadvertant access by transparent code
///
/// Called by critical methods:
/// PenContext.Dispose
/// PenContext.Enable
/// PenContext.Disable
///
///
[SecurityCritical]
internal static PenThread GetPenThreadForPenContext(PenContext penContext)
{
// Create the threadstatic DynamicRendererThreadManager as needed for calling thread.
// It only creates one
if (_penThreadPool == null)
{
_penThreadPool = new PenThreadPool();
}
return _penThreadPool.GetPenThreadForPenContextHelper(penContext); // Adds to weak ref list if creating new one.
}
/////////////////////////////////////////////////////////////////////
///
///
///
///
/// Critical - marking this critical to prevent inadvertant
/// access by transparent code
///
///
[SecurityCritical]
private List _penThreadWeakRefList;
/////////////////////////////////////////////////////////////////////
///
///
///
///
/// Critical - Initializes critical data: m_PenThreads
///
///
[SecurityCritical]
internal PenThreadPool()
{
_penThreadWeakRefList = new List();
}
///
/// Critical - Calls SecurityCritical code (PenThread constructor).
/// Called by BeginService.
/// TreatAsSafe boundry is Stylus.EnableCore, Stylus.RegisterHwndForInput
/// and HwndWrapperHook class (via HwndSource.InputFilterMessage).
///
[SecurityCritical]
private PenThread GetPenThreadForPenContextHelper(PenContext penContext)
{
bool needCleanup = false;
PenThread penThread = null;
int i;
// Scan existing penthreads to see if we have an available slot for context.
for (i=0; i < _penThreadWeakRefList.Count; i++)
{
PenThread penThreadFound = _penThreadWeakRefList[i].Target as PenThread;
if (penThreadFound == null)
{
needCleanup = true;
}
else
{
// See if we can use this one
if (penContext == null || penThreadFound.AddPenContext(penContext))
{
// We can use this one.
penThread = penThreadFound;
break;
}
}
}
if (needCleanup)
{
// prune invalid refs
for (i=_penThreadWeakRefList.Count - 1; i >= 0; i--)
{
if (_penThreadWeakRefList[i].Target == null)
{
_penThreadWeakRefList.RemoveAt(i);
}
}
}
if (penThread == null)
{
penThread = new PenThread();
// Make sure we add this context to the penthread
if (penContext != null)
{
penThread.AddPenContext(penContext);
}
_penThreadWeakRefList.Add(new WeakReference(penThread));
}
return penThread;
}
}
}
// 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
- CustomAttributeBuilder.cs
- WebControl.cs
- Timer.cs
- AccessDataSource.cs
- LicenseManager.cs
- QilValidationVisitor.cs
- Vector3DConverter.cs
- SpAudioStreamWrapper.cs
- CancellationHandler.cs
- CodeIdentifier.cs
- ResourceType.cs
- MetadataSerializer.cs
- DetailsViewDeletedEventArgs.cs
- Activity.cs
- TableLayoutStyleCollection.cs
- GeneralTransformGroup.cs
- XmlQueryType.cs
- SoapSchemaExporter.cs
- BrowsableAttribute.cs
- SqlTypeConverter.cs
- HtmlContainerControl.cs
- ResourceWriter.cs
- ListChunk.cs
- ServiceEndpointElementCollection.cs
- ChannelServices.cs
- EntityDataSourceWrapper.cs
- EasingFunctionBase.cs
- QuaternionRotation3D.cs
- MobileFormsAuthentication.cs
- _CacheStreams.cs
- OleDbFactory.cs
- FirstMatchCodeGroup.cs
- FormsAuthenticationUserCollection.cs
- HelpEvent.cs
- KeyValuePair.cs
- OptimizerPatterns.cs
- ConfigXmlComment.cs
- EntityViewContainer.cs
- CmsInterop.cs
- Parser.cs
- GeometryDrawing.cs
- XmlSchemaProviderAttribute.cs
- SourceLineInfo.cs
- Vector3dCollection.cs
- CodeStatementCollection.cs
- remotingproxy.cs
- MulticastIPAddressInformationCollection.cs
- SiteMapDataSourceView.cs
- FileLevelControlBuilderAttribute.cs
- WMICapabilities.cs
- LayoutUtils.cs
- XmlCustomFormatter.cs
- base64Transforms.cs
- ConstructorNeedsTagAttribute.cs
- GridViewSortEventArgs.cs
- ComboBoxAutomationPeer.cs
- PackageDigitalSignatureManager.cs
- FactoryGenerator.cs
- XhtmlBasicControlAdapter.cs
- HtmlInputPassword.cs
- EntitySqlQueryCacheKey.cs
- JsonReaderWriterFactory.cs
- ReadOnlyObservableCollection.cs
- SqlClientFactory.cs
- SqlDependency.cs
- SqlTriggerContext.cs
- AuthorizationRule.cs
- ErrorHandlerFaultInfo.cs
- DataSourceControl.cs
- ObjectDataSourceFilteringEventArgs.cs
- PipelineModuleStepContainer.cs
- DataServiceException.cs
- MsmqBindingFilter.cs
- TemplateControlBuildProvider.cs
- AppSettings.cs
- _FtpControlStream.cs
- TextBlock.cs
- ManifestSignatureInformation.cs
- StateManagedCollection.cs
- ReverseInheritProperty.cs
- ErrorFormatterPage.cs
- BamlLocalizationDictionary.cs
- UIElementCollection.cs
- WindowsFormsSynchronizationContext.cs
- DateTimeFormatInfo.cs
- BaseTreeIterator.cs
- StateItem.cs
- CodeMethodInvokeExpression.cs
- DataContractSet.cs
- Debugger.cs
- RowsCopiedEventArgs.cs
- EventArgs.cs
- CodeLinePragma.cs
- ContextProperty.cs
- ProfileProvider.cs
- CombinedGeometry.cs
- _CommandStream.cs
- ConnectorSelectionGlyph.cs
- DefaultTextStoreTextComposition.cs
- keycontainerpermission.cs