Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this be used in Console app? #37

Open
airadam opened this issue Dec 18, 2023 · 1 comment
Open

Can this be used in Console app? #37

airadam opened this issue Dec 18, 2023 · 1 comment

Comments

@airadam
Copy link

airadam commented Dec 18, 2023

I've been trying to use this library in a .NET 7.0 Windows console app, but even after registering a simple delegate against ClipboardChanged, I can't get it to fire at all. As the initial documentation describes using it in VS with the Designer, I thought I'd better check - can I expect it to work at all in my use case, or will it only work in a Forms app or similar?

using System;
using WK.Libraries.SharpClipboardNS;

namespace ExampleApp
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Starting.");
            var clipboard = new SharpClipboard();
            clipboard.ClipboardChanged += ClipboardChanged;

            while(true)
            {
            }
        }

        private static void ClipboardChanged(Object sender, SharpClipboard.ClipboardChangedEventArgs e)
        {
            Console.WriteLine("Change detected.");
            Console.WriteLine(e.Content.ToString());
        }
    }
}

Thanks!

@Salmakis
Copy link

Salmakis commented Jun 12, 2024

it works for me, but needed to make it [STAThread]
also i got the target framework to the one with -windows in my csproj file.

i.e.
<TargetFramework>net7.0</TargetFramework>
to
<TargetFramework>net7.0-windows</TargetFramework>

(works with 8.0 also so far)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants