From dc7af3751131eb07848fce615010cc6057278f10 Mon Sep 17 00:00:00 2001 From: dotnet-bot Date: Mon, 27 Apr 2015 13:40:15 -0700 Subject: [PATCH] Move System.Runtime.InteropServices partial facade into FxCore\Open Checked in by erme [tfs-changeset: 1460707] --- .../src/Resources/Strings.resx | 135 ++++++++++++++++++ ...tem.Runtime.InteropServices.CoreCLR.csproj | 42 ++++++ .../InteropServices/ComAwareEventInfo.cs | 134 +++++++++++++++++ .../InteropServices/ComTypes/IAdviseSink.cs | 54 +++++++ .../ComTypes/IEnumFormatETC.cs | 46 ++++++ .../Runtime/InteropServices/ComTypes/advf.cs | 20 +++ .../InteropServices/ComTypes/datadir.cs | 11 ++ .../InteropServices/ComTypes/dvaspect.cs | 14 ++ .../InteropServices/ComTypes/formatetc.cs | 17 +++ .../InteropServices/ComTypes/statdata.cs | 13 ++ .../InteropServices/ComTypes/stgmedium.cs | 13 ++ .../Runtime/InteropServices/ComTypes/tymed.cs | 18 +++ .../DefaultParameterValueAttribute.cs | 24 ++++ .../HandleCollector.CoreCLR.cs | 16 +++ .../InteropServices/HandleCollector.cs | 133 +++++++++++++++++ .../src/project.json | 5 + 16 files changed, 695 insertions(+) create mode 100644 src/System.Runtime.InteropServices/src/Resources/Strings.resx create mode 100644 src/System.Runtime.InteropServices/src/System.Runtime.InteropServices.CoreCLR.csproj create mode 100644 src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComAwareEventInfo.cs create mode 100644 src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/IAdviseSink.cs create mode 100644 src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/IEnumFormatETC.cs create mode 100644 src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/advf.cs create mode 100644 src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/datadir.cs create mode 100644 src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/dvaspect.cs create mode 100644 src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/formatetc.cs create mode 100644 src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/statdata.cs create mode 100644 src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/stgmedium.cs create mode 100644 src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/tymed.cs create mode 100644 src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs create mode 100644 src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/HandleCollector.CoreCLR.cs create mode 100644 src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/HandleCollector.cs create mode 100644 src/System.Runtime.InteropServices/src/project.json diff --git a/src/System.Runtime.InteropServices/src/Resources/Strings.resx b/src/System.Runtime.InteropServices/src/Resources/Strings.resx new file mode 100644 index 000000000000..5d63f6cd8a56 --- /dev/null +++ b/src/System.Runtime.InteropServices/src/Resources/Strings.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Handle collector count overflows or underflows. + + + Non-negative number required. + + + maximumThreshold cannot be less than initialThreshold. + + + Non-negative number required. + + + maximumThreshold cannot be less than initialThreshold. + + \ No newline at end of file diff --git a/src/System.Runtime.InteropServices/src/System.Runtime.InteropServices.CoreCLR.csproj b/src/System.Runtime.InteropServices/src/System.Runtime.InteropServices.CoreCLR.csproj new file mode 100644 index 000000000000..ee984c704eed --- /dev/null +++ b/src/System.Runtime.InteropServices/src/System.Runtime.InteropServices.CoreCLR.csproj @@ -0,0 +1,42 @@ + + + + + + System.Runtime.InteropServices + 4.0.20.0 + Library + true + ASP.NetCore, version=v5.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComAwareEventInfo.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComAwareEventInfo.cs new file mode 100644 index 000000000000..9e2e1d7ae8ac --- /dev/null +++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComAwareEventInfo.cs @@ -0,0 +1,134 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace System.Runtime.InteropServices +{ + [System.Security.SecuritySafeCritical] + public class ComAwareEventInfo : System.Reflection.EventInfo + { + private System.Reflection.EventInfo _innerEventInfo; + + public ComAwareEventInfo(Type type, string eventName) + { + _innerEventInfo = type.GetEvent(eventName); + } + + [System.Security.SecuritySafeCritical] + public override void AddEventHandler(object target, Delegate handler) + { + if (Marshal.IsComObject(target)) + { + // retrieve sourceIid and dispid + Guid sourceIid; + int dispid; + GetDataForComInvocation(_innerEventInfo, out sourceIid, out dispid); + System.Runtime.InteropServices.ComEventsHelper.Combine(target, sourceIid, dispid, handler); + } + else + { + // we are dealing with a managed object - just add the delegate through reflection + _innerEventInfo.AddEventHandler(target, handler); + } + } + + [System.Security.SecuritySafeCritical] + public override void RemoveEventHandler(object target, Delegate handler) + { + if (Marshal.IsComObject(target)) + { + // retrieve sourceIid and dispid + Guid sourceIid; + int dispid; + GetDataForComInvocation(_innerEventInfo, out sourceIid, out dispid); + + System.Runtime.InteropServices.ComEventsHelper.Remove(target, sourceIid, dispid, handler); + } + else + { + // we are dealing with a managed object - just add the delegate through relection + _innerEventInfo.RemoveEventHandler(target, handler); + } + } + + public override System.Reflection.EventAttributes Attributes + { + get { return _innerEventInfo.Attributes; } + } + + public override System.Reflection.MethodInfo GetAddMethod(bool nonPublic) + { + return _innerEventInfo.GetAddMethod(nonPublic); + } + + public override System.Reflection.MethodInfo GetRaiseMethod(bool nonPublic) + { + return _innerEventInfo.GetRaiseMethod(nonPublic); + } + + public override System.Reflection.MethodInfo GetRemoveMethod(bool nonPublic) + { + return _innerEventInfo.GetRemoveMethod(nonPublic); + } + + public override Type DeclaringType + { + get { return _innerEventInfo.DeclaringType; } + } + + public override object[] GetCustomAttributes(Type attributeType, bool inherit) + { + return _innerEventInfo.GetCustomAttributes(attributeType, inherit); + } + + public override object[] GetCustomAttributes(bool inherit) + { + return _innerEventInfo.GetCustomAttributes(inherit); + } + + public override bool IsDefined(Type attributeType, bool inherit) + { + return _innerEventInfo.IsDefined(attributeType, inherit); + } + + public override string Name + { + get { return _innerEventInfo.Name; } + } + + public override Type ReflectedType + { + get { return _innerEventInfo.ReflectedType; } + } + + private static void GetDataForComInvocation(System.Reflection.EventInfo eventInfo, out Guid sourceIid, out int dispid) + { + object[] comEventInterfaces = eventInfo.DeclaringType.GetCustomAttributes(typeof(ComEventInterfaceAttribute), false); + + if (comEventInterfaces == null || comEventInterfaces.Length == 0) + { + // TODO: event strings need to be localizable + throw new InvalidOperationException("event invocation for COM objects requires interface to be attributed with ComSourceInterfaceGuidAttribute"); + } + + if (comEventInterfaces.Length > 1) + { + // TODO: event strings need to be localizable + throw new System.Reflection.AmbiguousMatchException("more than one ComSourceInterfaceGuidAttribute found"); + } + + Type sourceItf = ((ComEventInterfaceAttribute)comEventInterfaces[0]).SourceInterface; + Guid guid = sourceItf.GUID; + + System.Reflection.MethodInfo methodInfo = sourceItf.GetMethod(eventInfo.Name); + Attribute dispIdAttribute = Attribute.GetCustomAttribute(methodInfo, typeof(DispIdAttribute)); + if (dispIdAttribute == null) + { + // TODO: event strings need to be localizable + throw new InvalidOperationException("event invocation for COM objects requires event to be attributed with DispIdAttribute"); + } + + sourceIid = guid; + dispid = ((DispIdAttribute)dispIdAttribute).Value; + } + } +} diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/IAdviseSink.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/IAdviseSink.cs new file mode 100644 index 000000000000..de1d1551ba0c --- /dev/null +++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/IAdviseSink.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace System.Runtime.InteropServices.ComTypes +{ + /// + /// The IAdviseSink interface enables containers and other objects to + /// receive notifications of data changes, view changes, and compound-document + /// changes occurring in objects of interest. Container applications, for + /// example, require such notifications to keep cached presentations of their + /// linked and embedded objects up-to-date. Calls to IAdviseSink methods are + /// asynchronous, so the call is sent and then the next instruction is executed + /// without waiting for the call's return. + /// + [ComImport] + [Guid("0000010F-0000-0000-C000-000000000046")] + [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] + public interface IAdviseSink + { + /// + /// Called by the server to notify a data object's currently registered + /// advise sinks that data in the object has changed. + /// + [PreserveSig] + void OnDataChange([In] ref FORMATETC format, [In] ref STGMEDIUM stgmedium); + + /// + /// Notifies an object's registered advise sinks that its view has changed. + /// + [PreserveSig] + void OnViewChange(int aspect, int index); + + /// + /// Called by the server to notify all registered advisory sinks that + /// the object has been renamed. + /// + [PreserveSig] + void OnRename(IMoniker moniker); + + /// + /// Called by the server to notify all registered advisory sinks that + /// the object has been saved. + /// + [PreserveSig] + void OnSave(); + + /// + /// Called by the server to notify all registered advisory sinks that the + /// object has changed from the running to the loaded state. + /// + [PreserveSig] + void OnClose(); + } +} diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/IEnumFormatETC.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/IEnumFormatETC.cs new file mode 100644 index 000000000000..48700fb1d0f2 --- /dev/null +++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/IEnumFormatETC.cs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace System.Runtime.InteropServices.ComTypes +{ + /// + /// The IEnumFORMATETC interface is used to enumerate an array of FORMATETC + /// structures. IEnumFORMATETC has the same methods as all enumerator interfaces: + /// Next, Skip, Reset, and Clone. + /// + [ComImport()] + [Guid("00000103-0000-0000-C000-000000000046")] + [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] + public interface IEnumFORMATETC + { + /// + /// Retrieves the next celt items in the enumeration sequence. If there are + /// fewer than the requested number of elements left in the sequence, it + /// retrieves the remaining elements. The number of elements actually + /// retrieved is returned through pceltFetched (unless the caller passed + /// in NULL for that parameter). + /// + [PreserveSig] + int Next(int celt, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] FORMATETC[] rgelt, [Out, MarshalAs(UnmanagedType.LPArray)] int[] pceltFetched); + + /// + /// Skips over the next specified number of elements in the enumeration sequence. + /// + [PreserveSig] + int Skip(int celt); + + /// + /// Resets the enumeration sequence to the beginning. + /// + [PreserveSig] + int Reset(); + + /// + /// Creates another enumerator that contains the same enumeration state as + /// the current one. Using this function, a client can record a particular + /// point in the enumeration sequence and then return to that point at a + /// later time. The new enumerator supports the same interface as the original one. + /// + void Clone(out IEnumFORMATETC newEnum); + } +} diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/advf.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/advf.cs new file mode 100644 index 000000000000..54f557d36e5a --- /dev/null +++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/advf.cs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace System.Runtime.InteropServices.ComTypes +{ + [Flags] + public enum ADVF + { + ADVF_NODATA = 1, + ADVF_PRIMEFIRST = 2, + ADVF_ONLYONCE = 4, + ADVF_DATAONSTOP = 64, + ADVFCACHE_NOHANDLER = 8, + ADVFCACHE_FORCEBUILTIN = 16, + ADVFCACHE_ONSAVE = 32 + } + // Note: ADVF_ONLYONCE and ADVF_PRIMEFIRST values conform with objidl.dll but are backwards from + // the Platform SDK documentation as of 07/21/2003. + // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/oen_a2z_8jxi.asp. +} diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/datadir.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/datadir.cs new file mode 100644 index 000000000000..be8d8fc1d963 --- /dev/null +++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/datadir.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace System.Runtime.InteropServices.ComTypes +{ + public enum DATADIR + { + DATADIR_GET = 1, + DATADIR_SET = 2 + } +} diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/dvaspect.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/dvaspect.cs new file mode 100644 index 000000000000..fdab04d043e5 --- /dev/null +++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/dvaspect.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace System.Runtime.InteropServices.ComTypes +{ + [Flags] + public enum DVASPECT + { + DVASPECT_CONTENT = 1, + DVASPECT_THUMBNAIL = 2, + DVASPECT_ICON = 4, + DVASPECT_DOCPRINT = 8 + } +} diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/formatetc.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/formatetc.cs new file mode 100644 index 000000000000..ec2f9fe42099 --- /dev/null +++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/formatetc.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace System.Runtime.InteropServices.ComTypes +{ + public struct FORMATETC + { + [MarshalAs(UnmanagedType.U2)] + public short cfFormat; + public IntPtr ptd; + [MarshalAs(UnmanagedType.U4)] + public DVASPECT dwAspect; + public int lindex; + [MarshalAs(UnmanagedType.U4)] + public TYMED tymed; + } +} diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/statdata.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/statdata.cs new file mode 100644 index 000000000000..3243ac318efe --- /dev/null +++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/statdata.cs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace System.Runtime.InteropServices.ComTypes +{ + public struct STATDATA + { + public FORMATETC formatetc; + public ADVF advf; + public IAdviseSink advSink; + public int connection; + } +} diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/stgmedium.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/stgmedium.cs new file mode 100644 index 000000000000..bffea0e4b842 --- /dev/null +++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/stgmedium.cs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace System.Runtime.InteropServices.ComTypes +{ + public struct STGMEDIUM + { + public TYMED tymed; + public IntPtr unionmember; + [MarshalAs(UnmanagedType.IUnknown)] + public object pUnkForRelease; + } +} diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/tymed.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/tymed.cs new file mode 100644 index 000000000000..ba687a5ef316 --- /dev/null +++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/tymed.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace System.Runtime.InteropServices.ComTypes +{ + [Flags] + public enum TYMED + { + TYMED_HGLOBAL = 1, + TYMED_FILE = 2, + TYMED_ISTREAM = 4, + TYMED_ISTORAGE = 8, + TYMED_GDI = 16, + TYMED_MFPICT = 32, + TYMED_ENHMF = 64, + TYMED_NULL = 0 + } +} diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs new file mode 100644 index 000000000000..0fdf29709700 --- /dev/null +++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/DefaultParameterValueAttribute.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace System.Runtime.InteropServices +{ + // + // The DefaultParameterValueAttribute is used in C# to set + // the default value for parameters when calling methods + // from other languages. This is particularly useful for + // methods defined in COM interop interfaces. + // + [AttributeUsageAttribute(AttributeTargets.Parameter)] + public sealed class DefaultParameterValueAttribute : Attribute + { + public DefaultParameterValueAttribute(object value) + { + _value = value; + } + + public object Value { get { return _value; } } + + private object _value; + } +} diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/HandleCollector.CoreCLR.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/HandleCollector.CoreCLR.cs new file mode 100644 index 000000000000..bca40e2494c4 --- /dev/null +++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/HandleCollector.CoreCLR.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Threading; + +namespace System.Runtime.InteropServices +{ + // CoreCLR-specific HandleCollector implementation + public sealed partial class HandleCollector + { + private void Sleep(int milliseconds) + { + Thread.Sleep(milliseconds); + } + } +} \ No newline at end of file diff --git a/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/HandleCollector.cs b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/HandleCollector.cs new file mode 100644 index 000000000000..0397bcce1c9b --- /dev/null +++ b/src/System.Runtime.InteropServices/src/System/Runtime/InteropServices/HandleCollector.cs @@ -0,0 +1,133 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Threading; + +namespace System.Runtime.InteropServices +{ + public sealed partial class HandleCollector + { + private const int deltaPercent = 10; // this is used for increasing the threshold. + private string _name; + private int _initialThreshold; + private int _maximumThreshold; + private int _threshold; + private int _handleCount; + + private int[] _gc_counts = new int[3]; + private int _gc_gen = 0; + + public HandleCollector(string name, int initialThreshold) : + this(name, initialThreshold, int.MaxValue) + { + } + + public HandleCollector(string name, int initialThreshold, int maximumThreshold) + { + if (initialThreshold < 0) + { + throw new ArgumentOutOfRangeException("initialThreshold", SR.Arg_NeedNonNegNumRequired); + } + + if (maximumThreshold < 0) + { + throw new ArgumentOutOfRangeException("maximumThreshold", SR.Arg_NeedNonNegNumRequired); + } + + if (initialThreshold > maximumThreshold) + { + throw new ArgumentException(SR.Arg_InvalidThreshold); + } + + if (name != null) + { + _name = name; + } + else + { + _name = String.Empty; + } + + _initialThreshold = initialThreshold; + _maximumThreshold = maximumThreshold; + _threshold = initialThreshold; + _handleCount = 0; + } + + public int Count { get { return _handleCount; } } + + public int InitialThreshold { get { return _initialThreshold; } } + + public int MaximumThreshold { get { return _maximumThreshold; } } + + public string Name { get { return _name; } } + + public void Add() + { + int gen_collect = -1; + Interlocked.Increment(ref _handleCount); + if (_handleCount < 0) + { + throw new InvalidOperationException(SR.InvalidOperation_HCCountOverflow); + } + + if (_handleCount > _threshold) + { + lock (this) + { + _threshold = _handleCount + (_handleCount / deltaPercent); + gen_collect = _gc_gen; + if (_gc_gen < 2) + { + _gc_gen++; + } + } + } + + if ((gen_collect >= 0) && + ((gen_collect == 0) || + (_gc_counts[gen_collect] == GC.CollectionCount(gen_collect)))) + { + GC.Collect(gen_collect); + Sleep(10 * gen_collect); + } + + //don't bother with gen0. + for (int i = 1; i < 3; i++) + { + _gc_counts[i] = GC.CollectionCount(i); + } + } + + public void Remove() + { + Interlocked.Decrement(ref _handleCount); + if (_handleCount < 0) + { + throw new InvalidOperationException(SR.InvalidOperation_HCCountOverflow); + } + + int newThreshold = _handleCount + _handleCount / deltaPercent; + if (newThreshold < (_threshold - _threshold / deltaPercent)) + { + lock (this) + { + if (newThreshold > _initialThreshold) + { + _threshold = newThreshold; + } + else + { + _threshold = _initialThreshold; + } + _gc_gen = 0; + } + } + + for (int i = 1; i < 3; i++) + { + _gc_counts[i] = GC.CollectionCount(i); + } + } + } +} diff --git a/src/System.Runtime.InteropServices/src/project.json b/src/System.Runtime.InteropServices/src/project.json new file mode 100644 index 000000000000..54912e4a28f7 --- /dev/null +++ b/src/System.Runtime.InteropServices/src/project.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "Microsoft.DotNet.CoreCLR": "1.0.0-prerelease" + } +} \ No newline at end of file