Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > BOOK: Beginning Visual C# 2010
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Visual C# 2010
This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2010 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 14th, 2011, 12:42 PM
Authorized User
Points: 149, Level: 2
Points: 149, Level: 2 Points: 149, Level: 2 Points: 149, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Location: Belgrade,Serbia
Posts: 34
Thanks: 14
Thanked 0 Times in 0 Posts
Default Chapter 21 Try it out,page 718

OnRenamed Metod throws an error:

public void OnRenamed(object source, RenamedEventArgs e)
{
try
{
StreamWriter sw = new StreamWriter(@"C:\FileLogs\Log.txt", true);
sw.WriteLine("File: {0} {1}", e.OldName, e.FullPath);
sw.Close();
this.BeginInvoke(new updatewatchertextdelegate(UPDATEWATCHTEXT), "wrote renamed event to log");
}

catch (IOException)
{
this.BeginInvoke(new updatewatchertextdelegate(UPDATEWATCHTEXT), "error writing to log");
}

}





Error 1 No overload for 'OnRenamed' matches delegate 'System.IO.FileSystemEventHandler' C:\source\Chapter21\filewatch\filewatch\Form1.cs 91 37 filewatch
  #2 (permalink)  
Old December 14th, 2011, 04:55 PM
Wrox Author
Points: 1,163, Level: 13
Points: 1,163, Level: 13 Points: 1,163, Level: 13 Points: 1,163, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2010
Location: Austria
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

To give you information on how to find this error - what does this error give on information?
Error 1 No overload for 'OnRenamed' matches delegate 'System.IO.FileSystemEventHandler'
This means that the parameters and return types of the OnRenamed method do not match the parameters and return types defined by the FileSystemEventHandler.

The method OnRenamed is defined with a void return type and object, RenamedEventArgs parameters. The FileSystemEventHandler delegate is defined this way:
Code:
public delegate void FileSystemEventHandler(object sender, FileSystemEventArgs e);
So the second parameter of OnRenamed could be changed to FileSystemEventArgs instead of RenamedEventArgs.

However, checking further where the method OnRenamed is applied to, it should be with the Renamed event of the FileSystemWatcher. This event is of type RenamedEventHandler. The RenamedEventHandler delegate matches the parameters you've defined with the OnRenamed method. So you probably assigned the OnRenamed method to a different event that is of type FileSystemEventHandler, e.g. Deleted, Changed, or Created.
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel
The Following User Says Thank You to ChristianNagel For This Useful Post:
dampyr (December 15th, 2011)
  #3 (permalink)  
Old December 15th, 2011, 06:21 AM
Authorized User
Points: 149, Level: 2
Points: 149, Level: 2 Points: 149, Level: 2 Points: 149, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Location: Belgrade,Serbia
Posts: 34
Thanks: 14
Thanked 0 Times in 0 Posts
Default

I have found error:

this.watcher.Renamed += new RenamedEventHandler(this.onrenamed);


instead of " RenamedEventHandler",i wrote "FileSystemEventHandler"
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 21 Try it out,page 693 dampyr BOOK: Beginning Visual C# 2010 0 December 11th, 2011 09:44 AM
list_entry(), page 21 logicman112 BOOK: Professional Linux Kernel Architecture ISBN: 978-0-470-34343-2 1 March 19th, 2009 03:56 AM



All times are GMT -4. The time now is 10:22 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.