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

How can I do this with FileSystemWatcher

Hi

I have th following code:

class MyClass
{
private string filename;
public int SetInfo (string FileName)
{
filename = FileName;
}

public MyClass ()
{
FileWatcher = new FileSystemWatcher ();
FileWatcher.NotifyFilter = NotifyFilters.FileName;

FileWatcher.Filter = "*.*";

FileWatcher.Path = "C:\\temp";

FileWatcher.Created += new FileSystemEventHandler (OnFileCreated);

}
private static void OnFileCreated(object source, FileSystemEventArgs e)
{

//How to call SetInfo ?


}

}

How can I call SetInfo without having to change it to a static function?
What are the options?
Thanks
Nov 16 '05 #1
3 3461
R.A,

You can call the method from where you are.

private static void OnFileCreated(object source, FileSystemEventArgs e)
{
this.SetInfo(e.Name);
}

Please note that the "this" keyword is optional.

HTH,

//Andreas

--
ANDREAS HÅKANSSON
STUDENT OF SOFTWARE ENGINEERING
andreas (at) selfinflicted.org
"R.A." <te**@citsecure.com> wrote in message news:eJ**************@TK2MSFTNGP09.phx.gbl...
Hi

I have th following code:

class MyClass
{
private string filename;
public int SetInfo (string FileName)
{
filename = FileName;
}

public MyClass ()
{
FileWatcher = new FileSystemWatcher ();
FileWatcher.NotifyFilter = NotifyFilters.FileName;

FileWatcher.Filter = "*.*";

FileWatcher.Path = "C:\\temp";

FileWatcher.Created += new FileSystemEventHandler (OnFileCreated);

}
private static void OnFileCreated(object source, FileSystemEventArgs e)
{

//How to call SetInfo ?


}

}

How can I call SetInfo without having to change it to a static function?
What are the options?
Thanks
Nov 16 '05 #2
HI RA,

First of all SetInfo will not compile cause you are not returning an
integer.
You cannot call it unless you make it static, or if you make the watcher
handler not static.

The only way that you dont have to change the declarations is if you
include a reference to the class itself as a static member:
class MyClass
{
static MyClass reference;

....
}
and then in the constructor you assign it:

public MyClass ()
{
reference = this;
}

then you can call the instance method using reference.SetInfo( ... )

Nevertheless, I think that you should not do this, if SetInfo is independend
of the instance you should make it a static member.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"R.A." <te**@citsecure.com> wrote in message
news:eJ**************@TK2MSFTNGP09.phx.gbl...
Hi

I have th following code:

class MyClass
{
private string filename;
public int SetInfo (string FileName)
{
filename = FileName;
}

public MyClass ()
{
FileWatcher = new FileSystemWatcher ();
FileWatcher.NotifyFilter = NotifyFilters.FileName;

FileWatcher.Filter = "*.*";

FileWatcher.Path = "C:\\temp";

FileWatcher.Created += new FileSystemEventHandler (OnFileCreated);

}
private static void OnFileCreated(object source, FileSystemEventArgs e)
{

//How to call SetInfo ?


}

}

How can I call SetInfo without having to change it to a static function?
What are the options?
Thanks

Nov 16 '05 #3
It doesn't let me because OnFileCreated is a static function!
"Andreas Håkansson" <andreas (at) selfinflicted.org> wrote in message news:O1**************@TK2MSFTNGP11.phx.gbl...
R.A,

You can call the method from where you are.

private static void OnFileCreated(object source, FileSystemEventArgs e)
{
this.SetInfo(e.Name);
}

Please note that the "this" keyword is optional.

HTH,

//Andreas

--
ANDREAS HÅKANSSON
STUDENT OF SOFTWARE ENGINEERING
andreas (at) selfinflicted.org
"R.A." <te**@citsecure.com> wrote in message news:eJ**************@TK2MSFTNGP09.phx.gbl...
Hi

I have th following code:

class MyClass
{
private string filename;
public int SetInfo (string FileName)
{
filename = FileName;
}

public MyClass ()
{
FileWatcher = new FileSystemWatcher ();
FileWatcher.NotifyFilter = NotifyFilters.FileName;

FileWatcher.Filter = "*.*";

FileWatcher.Path = "C:\\temp";

FileWatcher.Created += new FileSystemEventHandler (OnFileCreated);

}
private static void OnFileCreated(object source, FileSystemEventArgs e)
{

//How to call SetInfo ?


}

}

How can I call SetInfo without having to change it to a static function?
What are the options?
Thanks
Nov 16 '05 #4

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

Similar topics

2
by: Phil Galey | last post by:
I have a FileSystemWatcher that triggers when a PDF file is created. However, the creation of the PDF file is about a 7 or 8 second process ... I cannot refer to the file during that time because...
2
by: Jim Hubbard | last post by:
I want to develop an installation watcher to watch over programs as they install themselves to the PC. The FileSystemWatcher will enable me to see all files created or changed within any...
2
by: Paul | last post by:
Hi, I've been developing an application in VB.NET that uses the FileSystemWatcher and a popup notification in order to tell me when files have been downloaded. The FileSystemWatcher code in...
13
by: David | last post by:
I have been working on trying to write a directory watcher service. One of the requirments is that it be able to watch multiple directories, not sub directories of one parent directory, but just...
3
by: Stampede | last post by:
Hi, I write an application which waits for incomming files in a specified directory. I thought, that using the FileSystemWatcher would be the best, as it does exactly what I need. But now I have...
1
by: PadovaBoy | last post by:
Hi! I try to develop a simple system for monitoring a sub directory of a web site and remake an xml file every time a sub-dir change it's name. I don't wont to use a window.service because, i want...
7
by: Frank | last post by:
Hi, I am using FileSystemWatcher to track the change in a text file. Whenever I run the program I get 99% CPU utilization. The code doesn't do anything just sits and waits in a while loop until...
5
by: Goran Djuranovic | last post by:
Hi all, I have a file system watcher service that works fine on a local hard drive, but will not work across the network. I tried both: mapping the drive and "\\..." path both no luck. I don't...
5
by: =?Utf-8?B?Sm9obiBT?= | last post by:
I am trying to find out if there is a way to tell if there is already a filesystemwatcher (created by a webservice) monitoring a folder. I have a webservice that creates a filesystemwatcher,...
1
by: Lila Godel | last post by:
My VB.NET 2008 application is setup with a Sub Main and no forms. At run time a NotifyIcon is created with one context menu choice (Close which terminates app). I have no trouble running the...
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: 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...
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
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.