Autor Beitrag
ebber
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 239
Erhaltene Danke: 1

Win XP, Win 7
C# (VS 2010), Delphi (2007), Expression 4
BeitragVerfasst: Mo 06.10.08 14:00 
Hallo,

ich habe ein Textdokument, eine Logdatei eines anderen Programms. Ich möchte mit meinem Programm die Daten aus der Datei verarbeiten. Also immer wenn die Log Datei erweitert wird sollte mein Programm mitbekommen was drin steht. Ich könnte jetzt alle 5 min gucken ob noch das gleiche in der Datei steht, es sollte aber ziemlich schnell gehen, am besten < 1sek. Kann man sich da irgendein Event reinbauen oder sowas?

MfG
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: Mo 06.10.08 14:36 
Dafür ist die FileSystemWatcher-Klasse vorgesehen. Jürgen
ebber Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 239
Erhaltene Danke: 1

Win XP, Win 7
C# (VS 2010), Delphi (2007), Expression 4
BeitragVerfasst: Mo 06.10.08 15:17 
Danke, wusste nicht dass es sowas schon fertig gibt. Eben Microsoft.

Code Schnipsel, wenns jemand braucht:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            System.IO.FileSystemWatcher fsw = new System.IO.FileSystemWatcher("C:\\");
            fsw.Filter = "protocol.txt";    // "" für alles oder wildcards
            fsw.Changed += new System.IO.FileSystemEventHandler(fsw_Changed);
            fsw.EnableRaisingEvents = true;
        }

        void fsw_Changed(object sender, System.IO.FileSystemEventArgs e)
        {
            Console.WriteLine(e.Name + e.FullPath + e.ChangeType);
        }


MfG