473,382 Members | 1,423 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,382 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 3460
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.