By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

RaiseEvent in csharp

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
awk
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

Nov 15 '05 #2

P: n/a
awk
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

Nov 15 '05 #3

P: n/a
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


Nov 15 '05 #4

P: n/a
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


Nov 15 '05 #5

P: n/a
awk
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



Nov 15 '05 #6

P: n/a
awk
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



Nov 15 '05 #7

P: n/a
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
>
>



Nov 15 '05 #8

P: n/a
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
>
>



Nov 15 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.