473,396 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Difference between FileSystemEventHandler(OnChanged) and Onchanged

What is the difference between

watch.Changed += new FileSystemEventHandler(OnChanged);

and
watch.Changed += OnChanged;

?

Which form should I use ?

Andrus.
void WaitAndSaveFile(string file) {
using (FileSystemWatcher watch = new FileSystemWatcher()) {
watch.Path = Application.StartupPath;
watch.Filter = file;
watch.Changed += new FileSystemEventHandler(OnChanged);
// or watch.Changed += OnChanged; ? what is the difference ?

}

static void OnChanged(object sender, FileSystemEventArgs e) {
Console.WriteLine("\tNOTIFICATION: " + e.FullPath +
"' was " + e.ChangeType.ToString());
Console.WriteLine();
}

Jun 15 '07 #1
2 3300
Andrus <ko********@hot.eewrote:
What is the difference between

watch.Changed += new FileSystemEventHandler(OnChanged);

and
watch.Changed += OnChanged;

?

Which form should I use ?
There's no difference in the code generated. In C# 1, the first form
was all you could use. C# 2 has delegate type inference and implicit
conversions from "method group" expressions to delegates, which is
what's happening in the second version. I always use the second version
where possible.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 15 '07 #2
There is no difference in 2.0 you can use shortcut like watch.Changed +=
OnChanged
"Andrus" <ko********@hot.eewrote in message
news:e%***************@TK2MSFTNGP06.phx.gbl...
What is the difference between

watch.Changed += new FileSystemEventHandler(OnChanged);

and
watch.Changed += OnChanged;

?

Which form should I use ?

Andrus.
void WaitAndSaveFile(string file) {
using (FileSystemWatcher watch = new FileSystemWatcher()) {
watch.Path = Application.StartupPath;
watch.Filter = file;
watch.Changed += new FileSystemEventHandler(OnChanged);
// or watch.Changed += OnChanged; ? what is the difference ?

}

static void OnChanged(object sender, FileSystemEventArgs e) {
Console.WriteLine("\tNOTIFICATION: " + e.FullPath +
"' was " + e.ChangeType.ToString());
Console.WriteLine();
}

Jun 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Troy Murphy | last post by:
How do I prevent the FileSystemWatcher event to keep firing while the file is being created? When copying a file to the watched folder, the event fires a dozen or more times! Also, the...
8
by: Nicolas | last post by:
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...
3
by: Ron Vecchi | last post by:
Hi all, Can someone point me in the direction on this one, resources or examples. I am writing a Windows Service to monitor a folder. When I file is modified within the folder or any subfolders...
0
by: Erik Herje via .NET 247 | last post by:
Hi, I have a Windows Service written in C# whos purpose is to sniff a folder to look for changes in the folder. If a file is created or changed, it should get its name and start an object the...
0
by: zfeld | last post by:
My program has two instances of a control have fileSystemWatchers that are set to monitor the same directory for changes. When they are watching a directory on the local machine, it works fine, two...
1
by: TD | last post by:
I'm watching a folder for new files. When the files arrive, I want to wait until it is done being written to and then move it. Every time I move a file into the test folder, it triggers 3 calls...
3
by: Peter Kirk | last post by:
Hi I am trying to use FileSystemWatcher to watch for changes in a directory. The problem I am exepriencing is a double firing of an OnChanged event when a file is opened, edited, and saved. Why...
1
by: Peter Kirk | last post by:
Hi I am trying to use FileSystemWatcher to watch for changes in a directory. The problem I am exepriencing is a double firing of an OnChanged event when a file is opened, edited, and saved. Why...
4
by: Andrus | last post by:
To reporoduce, run the code. Observed: Form is shown Expected: message box should displayed. How to fix ? Andrus.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.