【发布时间】:2021-01-20 08:06:07
【问题描述】:
我正在尝试使用 .NET 控制台应用程序监视剪贴板更改。 因此我使用“SharpClipboard”库和以下代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WK.Libraries.SharpClipboardNS;
using System.Threading;
using System.Diagnostics;
namespace MeinKasten2Printer
{
class Program
{
[STAThreadAttribute]
static void Main(string[] args)
{
var clipboard = new SharpClipboard();
// Attach your code to the ClipboardChanged event to listen to cuts/copies.
clipboard.ClipboardChanged += ClipboardChanged;
}
public static void ClipboardChanged(Object sender, SharpClipboard.ClipboardChangedEventArgs e)
{
// Is the content copied of text type?
if (e.ContentType == SharpClipboard.ContentTypes.Text)
{
// Get the cut/copied text.
Debug.WriteLine(e.Content.ToString());
}
}
}
}
问题是应用程序在执行后立即关闭。 我做错了什么?它应该输出所有的文本更改。
【问题讨论】:
-
The problem is that the application is immediately closing after execution.这就是你告诉它的。添加事件处理程序后没有任何反应,因此Main立即退出并且应用程序终止 -
添加 Console.ReadLine();作为 main 方法的最后一行
-
现在控制台保持打开状态,但不输出复制的文本......也许我如何实现 SharpClipboard 功能还有另一个错误..
标签: .net console-application clipboard