How do I do a RaiseEvent in csharp
I'm ok in VB but csharp confused me a lot.
******* code ********
private FileSystemWatcher watcher = new FileSystemWatcher();
public delegate void Changed(WatcherChangeTypes exch);
public delegate void Created(string fileName);
public delegate void ReCreated(string OldName, string newName);
public delegate void OverRun(string Message);
public FileWatcher()
{
watcher.Path = "C:\\";
//* Watch for changes in LastAccess and LastWrite times, and
// the renaming of files or directories. */
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch text files.
watcher.Filter = "*.txt";
// Add event handlers.
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
watcher.Error += new ErrorEventHandler(OnError);
// Begin watching.
watcher.EnableRaisingEvents = true;
}
protected virtual void OnChanged(object sender, FileSystemEventArgs e)
{
///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//Changed(e.ChangeType);
}
protected virtual void OnCreated(object sender, FileSystemEventArgs e)
{
///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//RaiseEvent Created(e.FullPath);
}
protected virtual void OnRenamed(object sender , RenamedEventArgs a)
{
///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//RaiseEvent ReCreated(e.OldFullPath, e.FullPath);
}
Thank you 8 10073
You havent declared an event of type one of your delegates in your code.
eg
public event Changed FileWatcherChanged;
and you raise this
protected virtual void OnChanged(object sender, FileSystemEventArgs e)
{
changed(e.ChangeType);
}
Regards,
A
"Nicolas" <nl*****@hotmail.com> wrote in message
news:Oh**************@TK2MSFTNGP11.phx.gbl... How do I do a RaiseEvent in csharp I'm ok in VB but csharp confused me a lot.
******* code ******** private FileSystemWatcher watcher = new FileSystemWatcher();
public delegate void Changed(WatcherChangeTypes exch); public delegate void Created(string fileName); public delegate void ReCreated(string OldName, string newName); public delegate void OverRun(string Message);
public FileWatcher() { watcher.Path = "C:\\";
//* Watch for changes in LastAccess and LastWrite times, and // the renaming of files or directories. */ watcher.NotifyFilter = NotifyFilters.LastAccess |
NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch text files. watcher.Filter = "*.txt";
// Add event handlers. watcher.Changed += new FileSystemEventHandler(OnChanged); watcher.Created += new FileSystemEventHandler(OnCreated); watcher.Deleted += new FileSystemEventHandler(OnChanged); watcher.Renamed += new RenamedEventHandler(OnRenamed); watcher.Error += new ErrorEventHandler(OnError);
// Begin watching. watcher.EnableRaisingEvents = true;
}
protected virtual void OnChanged(object sender, FileSystemEventArgs e) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //Changed(e.ChangeType); }
protected virtual void OnCreated(object sender, FileSystemEventArgs e) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //RaiseEvent Created(e.FullPath); }
protected virtual void OnRenamed(object sender , RenamedEventArgs a) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //RaiseEvent ReCreated(e.OldFullPath, e.FullPath); } Thank you
You havent declared an event of type one of your delegates in your code.
eg
public event Changed FileWatcherChanged;
and you raise this
protected virtual void OnChanged(object sender, FileSystemEventArgs e)
{
changed(e.ChangeType);
}
Regards,
A
"Nicolas" <nl*****@hotmail.com> wrote in message
news:Oh**************@TK2MSFTNGP11.phx.gbl... How do I do a RaiseEvent in csharp I'm ok in VB but csharp confused me a lot.
******* code ******** private FileSystemWatcher watcher = new FileSystemWatcher();
public delegate void Changed(WatcherChangeTypes exch); public delegate void Created(string fileName); public delegate void ReCreated(string OldName, string newName); public delegate void OverRun(string Message);
public FileWatcher() { watcher.Path = "C:\\";
//* Watch for changes in LastAccess and LastWrite times, and // the renaming of files or directories. */ watcher.NotifyFilter = NotifyFilters.LastAccess |
NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch text files. watcher.Filter = "*.txt";
// Add event handlers. watcher.Changed += new FileSystemEventHandler(OnChanged); watcher.Created += new FileSystemEventHandler(OnCreated); watcher.Deleted += new FileSystemEventHandler(OnChanged); watcher.Renamed += new RenamedEventHandler(OnRenamed); watcher.Error += new ErrorEventHandler(OnError);
// Begin watching. watcher.EnableRaisingEvents = true;
}
protected virtual void OnChanged(object sender, FileSystemEventArgs e) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //Changed(e.ChangeType); }
protected virtual void OnCreated(object sender, FileSystemEventArgs e) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //RaiseEvent Created(e.FullPath); }
protected virtual void OnRenamed(object sender , RenamedEventArgs a) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //RaiseEvent ReCreated(e.OldFullPath, e.FullPath); } Thank you
Thanks, but now how do I call those functions from another form as all this
is in a dll now.
This is what I had in VB
////////////////// CODE \\\\\\\\\\\\\\\\\\\\
Imports it
Dim fw As New it_FileWatcher.FileWatcher()
AddHandler fw.Changed, AddressOf onChange
Sub onChange(ByVal changeType As System.IO.WatcherChangeTypes, ByVal
filename As String)
System.Diagnostics.Process.Start(filename)
End Sub
what should I do to get the same in csharp???
Thank you very much for the help.
"awk" <si*********@mbox.com.au> wrote in message
news:uN**************@tk2msftngp13.phx.gbl... You havent declared an event of type one of your delegates in your code.
eg public event Changed FileWatcherChanged;
and you raise this
protected virtual void OnChanged(object sender, FileSystemEventArgs e) { changed(e.ChangeType); }
Regards,
A
"Nicolas" <nl*****@hotmail.com> wrote in message news:Oh**************@TK2MSFTNGP11.phx.gbl... How do I do a RaiseEvent in csharp I'm ok in VB but csharp confused me a lot.
******* code ******** private FileSystemWatcher watcher = new FileSystemWatcher();
public delegate void Changed(WatcherChangeTypes exch); public delegate void Created(string fileName); public delegate void ReCreated(string OldName, string newName); public delegate void OverRun(string Message);
public FileWatcher() { watcher.Path = "C:\\";
//* Watch for changes in LastAccess and LastWrite times, and // the renaming of files or directories. */ watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch text files. watcher.Filter = "*.txt";
// Add event handlers. watcher.Changed += new FileSystemEventHandler(OnChanged); watcher.Created += new FileSystemEventHandler(OnCreated); watcher.Deleted += new FileSystemEventHandler(OnChanged); watcher.Renamed += new RenamedEventHandler(OnRenamed); watcher.Error += new ErrorEventHandler(OnError);
// Begin watching. watcher.EnableRaisingEvents = true;
}
protected virtual void OnChanged(object sender, FileSystemEventArgs e) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //Changed(e.ChangeType); }
protected virtual void OnCreated(object sender, FileSystemEventArgs e) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //RaiseEvent Created(e.FullPath); }
protected virtual void OnRenamed(object sender , RenamedEventArgs a) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //RaiseEvent ReCreated(e.OldFullPath, e.FullPath); } Thank you
Thanks, but now how do I call those functions from another form as all this
is in a dll now.
This is what I had in VB
////////////////// CODE \\\\\\\\\\\\\\\\\\\\
Imports it
Dim fw As New it_FileWatcher.FileWatcher()
AddHandler fw.Changed, AddressOf onChange
Sub onChange(ByVal changeType As System.IO.WatcherChangeTypes, ByVal
filename As String)
System.Diagnostics.Process.Start(filename)
End Sub
what should I do to get the same in csharp???
Thank you very much for the help.
"awk" <si*********@mbox.com.au> wrote in message
news:uN**************@tk2msftngp13.phx.gbl... You havent declared an event of type one of your delegates in your code.
eg public event Changed FileWatcherChanged;
and you raise this
protected virtual void OnChanged(object sender, FileSystemEventArgs e) { changed(e.ChangeType); }
Regards,
A
"Nicolas" <nl*****@hotmail.com> wrote in message news:Oh**************@TK2MSFTNGP11.phx.gbl... How do I do a RaiseEvent in csharp I'm ok in VB but csharp confused me a lot.
******* code ******** private FileSystemWatcher watcher = new FileSystemWatcher();
public delegate void Changed(WatcherChangeTypes exch); public delegate void Created(string fileName); public delegate void ReCreated(string OldName, string newName); public delegate void OverRun(string Message);
public FileWatcher() { watcher.Path = "C:\\";
//* Watch for changes in LastAccess and LastWrite times, and // the renaming of files or directories. */ watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch text files. watcher.Filter = "*.txt";
// Add event handlers. watcher.Changed += new FileSystemEventHandler(OnChanged); watcher.Created += new FileSystemEventHandler(OnCreated); watcher.Deleted += new FileSystemEventHandler(OnChanged); watcher.Renamed += new RenamedEventHandler(OnRenamed); watcher.Error += new ErrorEventHandler(OnError);
// Begin watching. watcher.EnableRaisingEvents = true;
}
protected virtual void OnChanged(object sender, FileSystemEventArgs e) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //Changed(e.ChangeType); }
protected virtual void OnCreated(object sender, FileSystemEventArgs e) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //RaiseEvent Created(e.FullPath); }
protected virtual void OnRenamed(object sender , RenamedEventArgs a) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //RaiseEvent ReCreated(e.OldFullPath, e.FullPath); } Thank you
Hi Nicolas
I think this is what your after.
it_FileWatcher.FileWatcher fw = new it_FileWatcher.FileWatcher();
fw.Changed += new it_FileWatcher.Changed(onChange);
private void onChange(System.IO.WatcherChangeTypes change, string filename)
{
System.Diagnostics.Process.Start(filename);
}
For more info check these out.
this link for some detail delegate and event coding in c#
with vb equivelants for comparison http://codeproject.com/dotnet/observerlistview.asp
and http://www.thecodeproject.com/csharp...te_bedtime.asp
Simon
"Nicolas" <nl*****@hotmail.com> wrote in message
news:uR*************@tk2msftngp13.phx.gbl... Thanks, but now how do I call those functions from another form as all
this is in a dll now.
This is what I had in VB ////////////////// CODE \\\\\\\\\\\\\\\\\\\\ Imports it
Dim fw As New it_FileWatcher.FileWatcher()
AddHandler fw.Changed, AddressOf onChange
Sub onChange(ByVal changeType As System.IO.WatcherChangeTypes, ByVal filename As String)
System.Diagnostics.Process.Start(filename)
End Sub
what should I do to get the same in csharp??? Thank you very much for the help.
"awk" <si*********@mbox.com.au> wrote in message news:uN**************@tk2msftngp13.phx.gbl... You havent declared an event of type one of your delegates in your
code. eg public event Changed FileWatcherChanged;
and you raise this
protected virtual void OnChanged(object sender, FileSystemEventArgs e) { changed(e.ChangeType); }
Regards,
A
"Nicolas" <nl*****@hotmail.com> wrote in message news:Oh**************@TK2MSFTNGP11.phx.gbl... How do I do a RaiseEvent in csharp I'm ok in VB but csharp confused me a lot.
******* code ******** private FileSystemWatcher watcher = new FileSystemWatcher();
public delegate void Changed(WatcherChangeTypes exch); public delegate void Created(string fileName); public delegate void ReCreated(string OldName, string newName); public delegate void OverRun(string Message);
public FileWatcher() { watcher.Path = "C:\\";
//* Watch for changes in LastAccess and LastWrite times, and // the renaming of files or directories. */ watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch text files. watcher.Filter = "*.txt";
// Add event handlers. watcher.Changed += new FileSystemEventHandler(OnChanged); watcher.Created += new FileSystemEventHandler(OnCreated); watcher.Deleted += new FileSystemEventHandler(OnChanged); watcher.Renamed += new RenamedEventHandler(OnRenamed); watcher.Error += new ErrorEventHandler(OnError);
// Begin watching. watcher.EnableRaisingEvents = true;
}
protected virtual void OnChanged(object sender, FileSystemEventArgs
e) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T
WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //Changed(e.ChangeType); }
protected virtual void OnCreated(object sender, FileSystemEventArgs e) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T
WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //RaiseEvent Created(e.FullPath); }
protected virtual void OnRenamed(object sender , RenamedEventArgs a) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T
WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //RaiseEvent ReCreated(e.OldFullPath, e.FullPath); } Thank you
Hi Nicolas
I think this is what your after.
it_FileWatcher.FileWatcher fw = new it_FileWatcher.FileWatcher();
fw.Changed += new it_FileWatcher.Changed(onChange);
private void onChange(System.IO.WatcherChangeTypes change, string filename)
{
System.Diagnostics.Process.Start(filename);
}
For more info check these out.
this link for some detail delegate and event coding in c#
with vb equivelants for comparison http://codeproject.com/dotnet/observerlistview.asp
and http://www.thecodeproject.com/csharp...te_bedtime.asp
Simon
"Nicolas" <nl*****@hotmail.com> wrote in message
news:uR*************@tk2msftngp13.phx.gbl... Thanks, but now how do I call those functions from another form as all
this is in a dll now.
This is what I had in VB ////////////////// CODE \\\\\\\\\\\\\\\\\\\\ Imports it
Dim fw As New it_FileWatcher.FileWatcher()
AddHandler fw.Changed, AddressOf onChange
Sub onChange(ByVal changeType As System.IO.WatcherChangeTypes, ByVal filename As String)
System.Diagnostics.Process.Start(filename)
End Sub
what should I do to get the same in csharp??? Thank you very much for the help.
"awk" <si*********@mbox.com.au> wrote in message news:uN**************@tk2msftngp13.phx.gbl... You havent declared an event of type one of your delegates in your
code. eg public event Changed FileWatcherChanged;
and you raise this
protected virtual void OnChanged(object sender, FileSystemEventArgs e) { changed(e.ChangeType); }
Regards,
A
"Nicolas" <nl*****@hotmail.com> wrote in message news:Oh**************@TK2MSFTNGP11.phx.gbl... How do I do a RaiseEvent in csharp I'm ok in VB but csharp confused me a lot.
******* code ******** private FileSystemWatcher watcher = new FileSystemWatcher();
public delegate void Changed(WatcherChangeTypes exch); public delegate void Created(string fileName); public delegate void ReCreated(string OldName, string newName); public delegate void OverRun(string Message);
public FileWatcher() { watcher.Path = "C:\\";
//* Watch for changes in LastAccess and LastWrite times, and // the renaming of files or directories. */ watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch text files. watcher.Filter = "*.txt";
// Add event handlers. watcher.Changed += new FileSystemEventHandler(OnChanged); watcher.Created += new FileSystemEventHandler(OnCreated); watcher.Deleted += new FileSystemEventHandler(OnChanged); watcher.Renamed += new RenamedEventHandler(OnRenamed); watcher.Error += new ErrorEventHandler(OnError);
// Begin watching. watcher.EnableRaisingEvents = true;
}
protected virtual void OnChanged(object sender, FileSystemEventArgs
e) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T
WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //Changed(e.ChangeType); }
protected virtual void OnCreated(object sender, FileSystemEventArgs e) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T
WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //RaiseEvent Created(e.FullPath); }
protected virtual void OnRenamed(object sender , RenamedEventArgs a) { ///////////////////////////////////////// THIS IS WHERE IT DOESN'T
WORK \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //RaiseEvent ReCreated(e.OldFullPath, e.FullPath); } Thank you
Thank a lot , work ok now!!!
"awk" <si*********@mbox.com.au> wrote in message
news:u9**************@TK2MSFTNGP10.phx.gbl... Hi Nicolas
I think this is what your after.
it_FileWatcher.FileWatcher fw = new it_FileWatcher.FileWatcher(); fw.Changed += new it_FileWatcher.Changed(onChange);
private void onChange(System.IO.WatcherChangeTypes change, string
filename) { System.Diagnostics.Process.Start(filename); }
For more info check these out.
this link for some detail delegate and event coding in c# with vb equivelants for comparison http://codeproject.com/dotnet/observerlistview.asp
and
http://www.thecodeproject.com/csharp...te_bedtime.asp
Simon
"Nicolas" <nl*****@hotmail.com> wrote in message news:uR*************@tk2msftngp13.phx.gbl... Thanks, but now how do I call those functions from another form as all this is in a dll now.
This is what I had in VB ////////////////// CODE \\\\\\\\\\\\\\\\\\\\ Imports it
Dim fw As New it_FileWatcher.FileWatcher()
AddHandler fw.Changed, AddressOf onChange
Sub onChange(ByVal changeType As System.IO.WatcherChangeTypes, ByVal filename As String)
System.Diagnostics.Process.Start(filename)
End Sub
what should I do to get the same in csharp??? Thank you very much for the help.
"awk" <si*********@mbox.com.au> wrote in message news:uN**************@tk2msftngp13.phx.gbl... You havent declared an event of type one of your delegates in your code. eg public event Changed FileWatcherChanged;
and you raise this
protected virtual void OnChanged(object sender, FileSystemEventArgs e) { changed(e.ChangeType); }
Regards,
A
"Nicolas" <nl*****@hotmail.com> wrote in message news:Oh**************@TK2MSFTNGP11.phx.gbl... > How do I do a RaiseEvent in csharp > I'm ok in VB but csharp confused me a lot. > > ******* code ******** > private FileSystemWatcher watcher = new FileSystemWatcher(); > > public delegate void Changed(WatcherChangeTypes exch); > public delegate void Created(string fileName); > public delegate void ReCreated(string OldName, string newName); > public delegate void OverRun(string Message); > > public FileWatcher() > { > watcher.Path = "C:\\"; > > //* Watch for changes in LastAccess and LastWrite times, and > // the renaming of files or directories. */ > watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite > | NotifyFilters.FileName | NotifyFilters.DirectoryName; > > // Only watch text files. > watcher.Filter = "*.txt"; > > // Add event handlers. > watcher.Changed += new FileSystemEventHandler(OnChanged); > watcher.Created += new FileSystemEventHandler(OnCreated); > watcher.Deleted += new FileSystemEventHandler(OnChanged); > watcher.Renamed += new RenamedEventHandler(OnRenamed); > watcher.Error += new ErrorEventHandler(OnError); > > // Begin watching. > watcher.EnableRaisingEvents = true; > > } > > protected virtual void OnChanged(object sender,
FileSystemEventArgs e) > { > ///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > //Changed(e.ChangeType); > } > > protected virtual void OnCreated(object sender, FileSystemEventArgs
e) > { > ///////////////////////////////////////// THIS IS WHERE IT DOESN'T
WORK > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > //RaiseEvent Created(e.FullPath); > } > > protected virtual void OnRenamed(object sender , RenamedEventArgs
a) > { > ///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > //RaiseEvent ReCreated(e.OldFullPath, e.FullPath); > } > > > > Thank you > >
Thank a lot , work ok now!!!
"awk" <si*********@mbox.com.au> wrote in message
news:u9**************@TK2MSFTNGP10.phx.gbl... Hi Nicolas
I think this is what your after.
it_FileWatcher.FileWatcher fw = new it_FileWatcher.FileWatcher(); fw.Changed += new it_FileWatcher.Changed(onChange);
private void onChange(System.IO.WatcherChangeTypes change, string
filename) { System.Diagnostics.Process.Start(filename); }
For more info check these out.
this link for some detail delegate and event coding in c# with vb equivelants for comparison http://codeproject.com/dotnet/observerlistview.asp
and
http://www.thecodeproject.com/csharp...te_bedtime.asp
Simon
"Nicolas" <nl*****@hotmail.com> wrote in message news:uR*************@tk2msftngp13.phx.gbl... Thanks, but now how do I call those functions from another form as all this is in a dll now.
This is what I had in VB ////////////////// CODE \\\\\\\\\\\\\\\\\\\\ Imports it
Dim fw As New it_FileWatcher.FileWatcher()
AddHandler fw.Changed, AddressOf onChange
Sub onChange(ByVal changeType As System.IO.WatcherChangeTypes, ByVal filename As String)
System.Diagnostics.Process.Start(filename)
End Sub
what should I do to get the same in csharp??? Thank you very much for the help.
"awk" <si*********@mbox.com.au> wrote in message news:uN**************@tk2msftngp13.phx.gbl... You havent declared an event of type one of your delegates in your code. eg public event Changed FileWatcherChanged;
and you raise this
protected virtual void OnChanged(object sender, FileSystemEventArgs e) { changed(e.ChangeType); }
Regards,
A
"Nicolas" <nl*****@hotmail.com> wrote in message news:Oh**************@TK2MSFTNGP11.phx.gbl... > How do I do a RaiseEvent in csharp > I'm ok in VB but csharp confused me a lot. > > ******* code ******** > private FileSystemWatcher watcher = new FileSystemWatcher(); > > public delegate void Changed(WatcherChangeTypes exch); > public delegate void Created(string fileName); > public delegate void ReCreated(string OldName, string newName); > public delegate void OverRun(string Message); > > public FileWatcher() > { > watcher.Path = "C:\\"; > > //* Watch for changes in LastAccess and LastWrite times, and > // the renaming of files or directories. */ > watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite > | NotifyFilters.FileName | NotifyFilters.DirectoryName; > > // Only watch text files. > watcher.Filter = "*.txt"; > > // Add event handlers. > watcher.Changed += new FileSystemEventHandler(OnChanged); > watcher.Created += new FileSystemEventHandler(OnCreated); > watcher.Deleted += new FileSystemEventHandler(OnChanged); > watcher.Renamed += new RenamedEventHandler(OnRenamed); > watcher.Error += new ErrorEventHandler(OnError); > > // Begin watching. > watcher.EnableRaisingEvents = true; > > } > > protected virtual void OnChanged(object sender,
FileSystemEventArgs e) > { > ///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > //Changed(e.ChangeType); > } > > protected virtual void OnCreated(object sender, FileSystemEventArgs
e) > { > ///////////////////////////////////////// THIS IS WHERE IT DOESN'T
WORK > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > //RaiseEvent Created(e.FullPath); > } > > protected virtual void OnRenamed(object sender , RenamedEventArgs
a) > { > ///////////////////////////////////////// THIS IS WHERE IT DOESN'T WORK > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > //RaiseEvent ReCreated(e.OldFullPath, e.FullPath); > } > > > > Thank you > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Guille |
last post by:
Hi all!
I'm having some weird behaviour in a .NET application i'm developing.
I'll try to explain:
I've created a Class that wraps an asynchronous socket.
When connect callback is called, i...
|
by: Nicolas |
last post by:
How do I call those functions from another form
This is what I had in VB
////////////////// CODE \\\\\\\\\\\\\\\\\\\\
Imports it
Dim fw As New it_FileWatcher.FileWatcher()
AddHandler...
|
by: shachar |
last post by:
hi all.
in vb.net i can write RaiseEvent.
can i do it in C# also?
how?
thanks - shachar.
|
by: Carl tam |
last post by:
Hi everyone,
I got a quite interesting problem myself and got stuck.
I have an aspx page with a windows user control with it.
in the Windows Control. I have a RaiseEvent statement,
say...
|
by: Lim |
last post by:
I've developed a program that raise an event. This program works fine on a Windows 2000 Professional PC. However when I try to run the program on a Windos XP Professional PC, the program will not...
|
by: dmoonme |
last post by:
I'm trying to rename some files in a directory. Pretty basic stuff -
renaming the files works fine but the problem I have is updated the text in
textbox. All I want to do is appendtext to a...
|
by: Martin |
last post by:
Hi all,
I'm having a problem when trying to raise an event in my custom control when
a toolstripbutton enable state changes. The problem is that although the
code to raise the event executes, my...
|
by: Terry Olsen |
last post by:
I have a program with a couple of long running processes that i'm calling on
a separate thread.
When the process is completed, I want to raise an event to tell the main
thread that it's done. I...
|
by: hzgt9b |
last post by:
Using VS2005, VB.NET,
I am developing a windows app. The application opens a couple of
forms. While the forms are open I want to raise some events, such as
logging errors - but I call RaiseEvent,...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |