RetriableClipboard.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / RetriableClipboard.cs / 1305376 / RetriableClipboard.cs

                            //---------------------------------------------------------------- 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//---------------------------------------------------------------

namespace System.Activities.Presentation 
{
    using System.Threading; 
    using System.Windows; 
    using System.Windows.Media.Imaging;
    using System.Runtime.InteropServices; 
    using System.Runtime;
    using System.Diagnostics;

    // The clipboard may be accessed by other processes. 
    // RetriableClipboard retries several times before giving up.
    static class RetriableClipboard 
    { 
        const int retryCount = 10;
        const int sleepTime = 50; 

        internal static IDataObject GetDataObject()
        {
            for (int i = 0; i < retryCount; i++) 
            {
                try 
                { 
                    return Clipboard.GetDataObject();
                } 
                catch (Exception err)
                {
                    Trace.WriteLine(err.ToString());
                    if (Fx.IsFatal(err)) 
                    {
                        throw; 
                    } 
                    Thread.Sleep(sleepTime);
                } 
            }
            return null;
        }
 
        internal static void SetDataObject(object data, bool copy)
        { 
            for (int i = 0; i < retryCount; i++) 
            {
                try 
                {
                    Clipboard.SetDataObject(data, copy);
                    return;
                } 
                catch (Exception err)
                { 
                    Trace.WriteLine(err.ToString()); 
                    if (Fx.IsFatal(err))
                    { 
                        throw;
                    }
                    Thread.Sleep(sleepTime);
                } 
            }
        } 
 
        internal static void SetImage(BitmapSource image)
        { 
            for (int i = 0; i < retryCount; i++)
            {
                try
                { 
                    Clipboard.SetImage(image);
                    return; 
                } 
                catch (Exception err)
                { 
                    Trace.WriteLine(err.ToString());
                    if (Fx.IsFatal(err))
                    {
                        throw; 
                    }
                    Thread.Sleep(sleepTime); 
                } 
            }
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//---------------------------------------------------------------- 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//---------------------------------------------------------------

namespace System.Activities.Presentation 
{
    using System.Threading; 
    using System.Windows; 
    using System.Windows.Media.Imaging;
    using System.Runtime.InteropServices; 
    using System.Runtime;
    using System.Diagnostics;

    // The clipboard may be accessed by other processes. 
    // RetriableClipboard retries several times before giving up.
    static class RetriableClipboard 
    { 
        const int retryCount = 10;
        const int sleepTime = 50; 

        internal static IDataObject GetDataObject()
        {
            for (int i = 0; i < retryCount; i++) 
            {
                try 
                { 
                    return Clipboard.GetDataObject();
                } 
                catch (Exception err)
                {
                    Trace.WriteLine(err.ToString());
                    if (Fx.IsFatal(err)) 
                    {
                        throw; 
                    } 
                    Thread.Sleep(sleepTime);
                } 
            }
            return null;
        }
 
        internal static void SetDataObject(object data, bool copy)
        { 
            for (int i = 0; i < retryCount; i++) 
            {
                try 
                {
                    Clipboard.SetDataObject(data, copy);
                    return;
                } 
                catch (Exception err)
                { 
                    Trace.WriteLine(err.ToString()); 
                    if (Fx.IsFatal(err))
                    { 
                        throw;
                    }
                    Thread.Sleep(sleepTime);
                } 
            }
        } 
 
        internal static void SetImage(BitmapSource image)
        { 
            for (int i = 0; i < retryCount; i++)
            {
                try
                { 
                    Clipboard.SetImage(image);
                    return; 
                } 
                catch (Exception err)
                { 
                    Trace.WriteLine(err.ToString());
                    if (Fx.IsFatal(err))
                    {
                        throw; 
                    }
                    Thread.Sleep(sleepTime); 
                } 
            }
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK