新手到C#這裏,第一次處理事件處理程序。我正在編寫的程序的一個步驟涉及每次在某個位置創建文件時更改剪貼板。以下是我想出迄今:FileSystemEventHandler後更改剪貼板
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using System.Windows.Forms;
namespace ConsoleApplication1
{
class Program
{
[STAThread]
public static void Main()
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"C:\Input\";
watcher.Filter = "*.csv";
watcher.Created += new FileSystemEventHandler(ProcessFile);
watcher.EnableRaisingEvents = true;
Console.ReadLine();
}
public static void ProcessFile(object source, FileSystemEventArgs e)
{
try
{
Clipboard.SetText("text");
}
catch (Exception exc)
{
Console.WriteLine(exc);
Console.ReadKey();
}
}
}
}
拋出異常當前線程不是STA模式,需要在Main方法被標記,但我相信,我這樣做。我如何在這裏更改剪貼板?