SetWonInitializationRace() private méthode

We keep tables for mappings between managed and WinRT streams to make sure to always return the same adapter for a given underlying stream. However, in order to avoid global locks on those tables, several instances of this type may be created and then can race to be entered into the appropriate map table. All except for the winning instances will be thrown away. However, we must ensure that when the losers are finalized, they do not dispose the underlying stream. To ensure that, we must call this method on the winner to notify it that it is safe to dispose the underlying stream.
private SetWonInitializationRace ( ) : void
Résultat void
Exemple #1
0
        private static NetFxToWinRtStreamAdapter AsWindowsRuntimeStreamInternalFactoryHelper(Stream stream)
        {
            Debug.Assert(stream != null);

            // Get the adapter for managed stream again (it may have been created concurrently).
            // If none exists yet, create a new one:
            NetFxToWinRtStreamAdapter adapter = s_netFxToWinRtAdapterMap.GetValue(stream, (str) => NetFxToWinRtStreamAdapter.Create(str));

            Debug.Assert(adapter != null);
            adapter.SetWonInitializationRace();

            return(adapter);
        }