iT邦幫忙

0

---delete

  • 分享至 

  • xImage
// Create a new FileSystemWatcher
FileProcessor fileProcessor = new FileProcessor();
FileSystemWatcher fileSystemWatcher1 = new FileSystemWatcher();

private void Form1_Load(object sender, EventArgs e)
{
    fileSystemWatcher1.Path = @"";
    fileSystemWatcher1.Filter = "";
    fileSystemWatcher1.IncludeSubdirectories = false;
    fileSystemWatcher1.Created += new FileSystemEventHandler(fileSystemWatcher1_Created);
    fileSystemWatcher1.EnableRaisingEvents = true;
}

private void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
{
    if (e.ChangeType == WatcherChangeTypes.Created)
    {
        fileProcessor.EnqueueFileName(e.FullPath);
    }
}

}


FileProcessor.cs

class FileProcessor : IDisposable
{
private EventWaitHandle eventWaitHandle = new AutoResetEvent(false);
private Thread worker;
private readonly
public void EnqueueFileName(string FileName)
{
// Enqueue the file name
lock (locker) fileNamesQueue.Enqueue(FileName);
eventWaitHandle.Set();
}
private void Work(){
while (true){
string fileName = null;
lock (locker)
if (fileNamesQueue.Count > 0){
fileN
Console.WriteLine(FileName);
}
}


public partial class Form1 : Form
{
    // Create a new FileS
        Console.WriteLine(FileName);
    }
    
}
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0
小魚
iT邦大師 1 級 ‧ 2021-11-29 20:16:26

麻煩了是甚麼意思?

雖然你的表達我看不大懂,
不過我猜也許interface可以滿足你的需求?

0
qaz11226633
iT邦新手 4 級 ‧ 2021-11-30 08:13:18

不懂~~
如果FORM2 要用
再把FileProcessor NEW出來啊

0
franx0722
iT邦新手 2 級 ‧ 2021-11-30 08:32:43

1.private 改 public 在 Form1.cs new一個不就完事了
2.靜態的方式去解決也可以
3.或直接在Form1.cs新增方法

我要發表回答

立即登入回答