473,320 Members | 2,071 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,320 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 3457
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.