473,385 Members | 1,855 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,385 software developers and data experts.

RaiseEvent in csharp

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
8 10069
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
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...
0
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...
6
by: shachar | last post by:
hi all. in vb.net i can write RaiseEvent. can i do it in C# also? how? thanks - shachar.
2
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...
2
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...
2
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...
3
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...
1
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...
10
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,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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...

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.