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

ASP.NET Application and FileSystemWatcher

P: n/a
J-T
We are working on an asp.net application which is a 3-tier application.I was
aksed to create a component which monitors a folder and gets the file and
pass them to a class library in our business logic layer(so far so good and
easy).I initialize my class which is using a FileSystemWatcher in my
Global.asax and everything works fine.I have found FileSystemWatcher class
not very reliable and sometimes it behavies unexpectedly.I'm afriad that it
brings down the whole application.Is there a better way of doing this
**Inside Asp.Net application**.I can't use antother application like windows
service or schedault taks.Everything needs to be done is ASP.NET
application.
Thanks a lot
Nov 19 '05 #1
Share this Question
Share on Google+
20 Replies


P: n/a
Hi J-T,
I have found FileSystemWatcher class not very reliable and sometimes it
behavies unexpectedly.I'm afriad that it brings down the whole
application.
The FileSystemWatcher class is very reliable. However, it uses events, which
are asynchronous to your application. Without knowing anything more about
how your code is written, I can't tell you much more. For example,
"Global.asax" is a file. The Global class that is generated when it is
compiled is a class. It contains a number of events, and you can't store a
class in an event. So, I have no idea where you're persisting your class, or
how. Also, you mentioned that you created a "component," which most probably
is not a "Component" in the literal .Net sense of the term. So, I know
nothing about that either.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... We are working on an asp.net application which is a 3-tier application.I
was aksed to create a component which monitors a folder and gets the file
and pass them to a class library in our business logic layer(so far so
good and easy).I initialize my class which is using a FileSystemWatcher in
my Global.asax and everything works fine.I have found FileSystemWatcher
class not very reliable and sometimes it behavies unexpectedly.I'm afriad
that it brings down the whole application.Is there a better way of doing
this **Inside Asp.Net application**.I can't use antother application like
windows service or schedault taks.Everything needs to be done is ASP.NET
application.
Thanks a lot

Nov 19 '05 #2

P: n/a
Are you sure you are on the right track? A FileSystemWatcher object has to
exist somewhere to be able to watch. An asp.net application doesn't exist
anywhere but between a client http request and the server response. A very
short time. Do you expect the watcher to catch something only when the
server is busy serving client requests?

Eliyahu
"J-T" <Ra****@microsft.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and
pass them to a class library in our business logic layer(so far so good and easy).I initialize my class which is using a FileSystemWatcher in my
Global.asax and everything works fine.I have found FileSystemWatcher class not very reliable and sometimes it behavies unexpectedly.I'm afriad that it brings down the whole application.Is there a better way of doing this
**Inside Asp.Net application**.I can't use antother application like windows service or schedault taks.Everything needs to be done is ASP.NET
application.
Thanks a lot

Nov 19 '05 #3

P: n/a
J-T
I forgot to say that directory which I monitor is a shared folder on the
netwrok.

Thanks
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
Are you sure you are on the right track? A FileSystemWatcher object has to
exist somewhere to be able to watch. An asp.net application doesn't exist
anywhere but between a client http request and the server response. A very
short time. Do you expect the watcher to catch something only when the
server is busy serving client requests?

Eliyahu
"J-T" <Ra****@microsft.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
We are working on an asp.net application which is a 3-tier application.I

was
aksed to create a component which monitors a folder and gets the file and
pass them to a class library in our business logic layer(so far so good

and
easy).I initialize my class which is using a FileSystemWatcher in my
Global.asax and everything works fine.I have found FileSystemWatcher

class
not very reliable and sometimes it behavies unexpectedly.I'm afriad that

it
brings down the whole application.Is there a better way of doing this
**Inside Asp.Net application**.I can't use antother application like

windows
service or schedault taks.Everything needs to be done is ASP.NET
application.
Thanks a lot


Nov 19 '05 #4

P: n/a
J-T
Here is what I have done .I have created a class and I instanciate that
class in Application_Start method of my Global.asax ere is the code:

********Gloabl.asax:
//Sets up a wacher on an specific shared folder to pickup zip files

IFPWatcherComponent ifpWacher=new
IFPWatcherComponent(ConfigurationSettings.AppSetti ngs[ "MonitorPath"]);

********MyClass:

/// </summary>
public class IFPWatcherComponent:BusinessObject
{
string PathToMonitor=null;

public IFPWatcherComponent(string PathToMonitor)
{

try
{
this.PathToMonitor = PathToMonitor;
//Check to see if Web.config has appropriate settings
if (this.PathToMonitor.Trim().Length==0 ) return;
// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo(this.PathToMonitor);
// Create the directory only if it does not already exist.
if (di.Exists == false)
di.Create();
// create an instance of FileSystemWatcher object and assign path to
monitor
FileSystemWatcher watcher = new FileSystemWatcher();
// set necessary filters
watcher.Path = this.PathToMonitor;
//Watch for changes in FileName
watcher.NotifyFilter = NotifyFilters.FileName;
// watch zip files
watcher.Filter = "*.zip";
//Add appropriate event handler
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.EnableRaisingEvents = true;
}
catch
{
throw;
}
}
private void OnCreated(object source, FileSystemEventArgs e)
{
FileStream oImg=null;
BinaryReader oBinaryReader=null;

Uploader uploader=new Uploader();
uploader.ComeFrom="88";
uploader.Comments="comment";
uploader.CreatedByUser="test";
uploader.FileName=e.Name;

try
{

oImg = new FileStream (e.FullPath,FileMode.Open,FileAccess.Read);
oBinaryReader = new BinaryReader(oImg);
byte[] oImgByteArray = oBinaryReader.ReadBytes((int) oImg.Length);
uploader.FileBody=oImgByteArray;

uploader.RecordType=Business.IFP.RecordType.IFP_UP LOAD;
uploader.Upload();
uploader=null;

}
catch(Exception ee)
{
*******************I don't know how to handle the exception
here??***********************
}
finally
{
if (oBinaryReader!=null) oBinaryReader.Close();
if (oImg!=null) oImg.Close();

}
}

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
Are you sure you are on the right track? A FileSystemWatcher object has to
exist somewhere to be able to watch. An asp.net application doesn't exist
anywhere but between a client http request and the server response. A very
short time. Do you expect the watcher to catch something only when the
server is busy serving client requests?

Eliyahu
"J-T" <Ra****@microsft.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
We are working on an asp.net application which is a 3-tier application.I

was
aksed to create a component which monitors a folder and gets the file and
pass them to a class library in our business logic layer(so far so good

and
easy).I initialize my class which is using a FileSystemWatcher in my
Global.asax and everything works fine.I have found FileSystemWatcher

class
not very reliable and sometimes it behavies unexpectedly.I'm afriad that

it
brings down the whole application.Is there a better way of doing this
**Inside Asp.Net application**.I can't use antother application like

windows
service or schedault taks.Everything needs to be done is ASP.NET
application.
Thanks a lot


Nov 19 '05 #5

P: n/a
This could be a problem. In my experience I could not get FileSystemWatcher
to work for network directories. Either it is not able to or some tricky
setting is needed.

Eliyahu

"J-T" <Ra****@microsft.com> wrote in message
news:Ov**************@tk2msftngp13.phx.gbl...
I forgot to say that directory which I monitor is a shared folder on the
netwrok.

Thanks
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
Are you sure you are on the right track? A FileSystemWatcher object has to exist somewhere to be able to watch. An asp.net application doesn't exist anywhere but between a client http request and the server response. A very short time. Do you expect the watcher to catch something only when the
server is busy serving client requests?

Eliyahu
"J-T" <Ra****@microsft.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
We are working on an asp.net application which is a 3-tier application.I
was
aksed to create a component which monitors a folder and gets the file
and pass them to a class library in our business logic layer(so far so good

and
easy).I initialize my class which is using a FileSystemWatcher in my
Global.asax and everything works fine.I have found FileSystemWatcher

class
not very reliable and sometimes it behavies unexpectedly.I'm afriad

that it
brings down the whole application.Is there a better way of doing this
**Inside Asp.Net application**.I can't use antother application like

windows
service or schedault taks.Everything needs to be done is ASP.NET
application.
Thanks a lot



Nov 19 '05 #6

P: n/a
Your FileSystemWatcher is scoped to the method in which you instantiate it.
That means that it goes out of scope and is not available as soon as the
method returns. It may hang around for a bit since you have no code to
dispose it at any point, but you need to bone up on scope and state. Here's
a primer:

Scope is the "area of influence" of a variable. In a class, you have global
and local variables. Global variables are declared outside of any methods,
and are therefore "visible" to all members of the class. Local variables are
declared inside a method, and are therefore "visible" only to other
variables within a single instance (call) of the method. Once the method
returns, it is removed from the stack, and everything in it becomes
available for garbage collection.

Note that this differs from public, private, etc. These are also definitions
of scope, but are more related to encapsulation. Public members of a class
are "visible" from other classes. Private members are not. Etc.

State refers to the persistence of an object (class instance or primitive)
in memory. Whenever an object is instantiated (created), it must reside in
memory somewhere. The lifetime of an object is limited to the lifetime of
the container in which it resides. A method is instantiated, just like a
variable, whenever you call it. And just like a variable, when it returns,
it is available for garbage collection. The only way to persist an instance
is to put it into something else that persists. Hence, ASP.Net, which
operates using HTTP, which is stateless, has mechanisms for maintaining
state, such as Session, Application, and ViewState.

The global.asax class, as I mentioned in my earlier reply, is a persistent
class, but it's methods are not. They are instantiated like any other
methods, and pass out of scope as soon as they return.

I hope you will study what I've said, and continue to study how OOP works as
you go. In the meantime, you need to understand how to persist your
FileSystemWatcher, as well as making sure that when you are finished with
it, you dispose it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:e5**************@TK2MSFTNGP14.phx.gbl...
Here is what I have done .I have created a class and I instanciate that
class in Application_Start method of my Global.asax ere is the code:

********Gloabl.asax:
//Sets up a wacher on an specific shared folder to pickup zip files

IFPWatcherComponent ifpWacher=new
IFPWatcherComponent(ConfigurationSettings.AppSetti ngs[ "MonitorPath"]);

********MyClass:

/// </summary>
public class IFPWatcherComponent:BusinessObject
{
string PathToMonitor=null;

public IFPWatcherComponent(string PathToMonitor)
{

try
{
this.PathToMonitor = PathToMonitor;
//Check to see if Web.config has appropriate settings
if (this.PathToMonitor.Trim().Length==0 ) return;
// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo(this.PathToMonitor);
// Create the directory only if it does not already exist.
if (di.Exists == false)
di.Create();
// create an instance of FileSystemWatcher object and assign path to
monitor
FileSystemWatcher watcher = new FileSystemWatcher();
// set necessary filters
watcher.Path = this.PathToMonitor;
//Watch for changes in FileName
watcher.NotifyFilter = NotifyFilters.FileName;
// watch zip files
watcher.Filter = "*.zip";
//Add appropriate event handler
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.EnableRaisingEvents = true;
}
catch
{
throw;
}
}
private void OnCreated(object source, FileSystemEventArgs e)
{
FileStream oImg=null;
BinaryReader oBinaryReader=null;

Uploader uploader=new Uploader();
uploader.ComeFrom="88";
uploader.Comments="comment";
uploader.CreatedByUser="test";
uploader.FileName=e.Name;

try
{

oImg = new FileStream (e.FullPath,FileMode.Open,FileAccess.Read);
oBinaryReader = new BinaryReader(oImg);
byte[] oImgByteArray = oBinaryReader.ReadBytes((int) oImg.Length);
uploader.FileBody=oImgByteArray;

uploader.RecordType=Business.IFP.RecordType.IFP_UP LOAD;
uploader.Upload();
uploader=null;

}
catch(Exception ee)
{
*******************I don't know how to handle the exception
here??***********************
}
finally
{
if (oBinaryReader!=null) oBinaryReader.Close();
if (oImg!=null) oImg.Close();

}
}

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
Are you sure you are on the right track? A FileSystemWatcher object has
to
exist somewhere to be able to watch. An asp.net application doesn't exist
anywhere but between a client http request and the server response. A
very
short time. Do you expect the watcher to catch something only when the
server is busy serving client requests?

Eliyahu
"J-T" <Ra****@microsft.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
We are working on an asp.net application which is a 3-tier application.I

was
aksed to create a component which monitors a folder and gets the file
and
pass them to a class library in our business logic layer(so far so good

and
easy).I initialize my class which is using a FileSystemWatcher in my
Global.asax and everything works fine.I have found FileSystemWatcher

class
not very reliable and sometimes it behavies unexpectedly.I'm afriad that

it
brings down the whole application.Is there a better way of doing this
**Inside Asp.Net application**.I can't use antother application like

windows
service or schedault taks.Everything needs to be done is ASP.NET
application.
Thanks a lot



Nov 19 '05 #7

P: n/a
J-T
So how would you monitor a network path in your asp.net application?
Thanks for your reply.
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:e7**************@TK2MSFTNGP12.phx.gbl...
This could be a problem. In my experience I could not get
FileSystemWatcher
to work for network directories. Either it is not able to or some tricky
setting is needed.

Eliyahu

"J-T" <Ra****@microsft.com> wrote in message
news:Ov**************@tk2msftngp13.phx.gbl...
I forgot to say that directory which I monitor is a shared folder on the
netwrok.

Thanks
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
> Are you sure you are on the right track? A FileSystemWatcher object has to > exist somewhere to be able to watch. An asp.net application doesn't exist > anywhere but between a client http request and the server response. A very > short time. Do you expect the watcher to catch something only when the
> server is busy serving client requests?
>
> Eliyahu
>
>
> "J-T" <Ra****@microsft.com> wrote in message
> news:%2****************@TK2MSFTNGP15.phx.gbl...
>> We are working on an asp.net application which is a 3-tier application.I > was
>> aksed to create a component which monitors a folder and gets the file and >> pass them to a class library in our business logic layer(so far so
>> good
> and
>> easy).I initialize my class which is using a FileSystemWatcher in my
>> Global.asax and everything works fine.I have found FileSystemWatcher
> class
>> not very reliable and sometimes it behavies unexpectedly.I'm afriad that > it
>> brings down the whole application.Is there a better way of doing this
>> **Inside Asp.Net application**.I can't use antother application like
> windows
>> service or schedault taks.Everything needs to be done is ASP.NET
>> application.
>>
>>
>> Thanks a lot
>>
>>
>
>



Nov 19 '05 #8

P: n/a
J-T
So you mean state wise and persistence wise,both,I will have problems by
using this code?

Do you have any idea how to persist my object.I want it to avaialable as
long as they application is up and working.So according to what you suggest
I will have to make the scope of my object some how global (not like the way
it is now) and also persist it in the memory for the time application is up.
Do I really have to dispose the object after the application gets stopped?

Thanks for super informative answer.

Ray
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u8****************@tk2msftngp13.phx.gbl...
Your FileSystemWatcher is scoped to the method in which you instantiate
it. That means that it goes out of scope and is not available as soon as
the method returns. It may hang around for a bit since you have no code to
dispose it at any point, but you need to bone up on scope and state.
Here's a primer:

Scope is the "area of influence" of a variable. In a class, you have
global and local variables. Global variables are declared outside of any
methods, and are therefore "visible" to all members of the class. Local
variables are declared inside a method, and are therefore "visible" only
to other variables within a single instance (call) of the method. Once the
method returns, it is removed from the stack, and everything in it becomes
available for garbage collection.

Note that this differs from public, private, etc. These are also
definitions of scope, but are more related to encapsulation. Public
members of a class are "visible" from other classes. Private members are
not. Etc.

State refers to the persistence of an object (class instance or primitive)
in memory. Whenever an object is instantiated (created), it must reside in
memory somewhere. The lifetime of an object is limited to the lifetime of
the container in which it resides. A method is instantiated, just like a
variable, whenever you call it. And just like a variable, when it returns,
it is available for garbage collection. The only way to persist an
instance is to put it into something else that persists. Hence, ASP.Net,
which operates using HTTP, which is stateless, has mechanisms for
maintaining state, such as Session, Application, and ViewState.

The global.asax class, as I mentioned in my earlier reply, is a persistent
class, but it's methods are not. They are instantiated like any other
methods, and pass out of scope as soon as they return.

I hope you will study what I've said, and continue to study how OOP works
as you go. In the meantime, you need to understand how to persist your
FileSystemWatcher, as well as making sure that when you are finished with
it, you dispose it.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:e5**************@TK2MSFTNGP14.phx.gbl...
Here is what I have done .I have created a class and I instanciate that
class in Application_Start method of my Global.asax ere is the code:

********Gloabl.asax:
//Sets up a wacher on an specific shared folder to pickup zip files

IFPWatcherComponent ifpWacher=new
IFPWatcherComponent(ConfigurationSettings.AppSetti ngs[ "MonitorPath"]);

********MyClass:

/// </summary>
public class IFPWatcherComponent:BusinessObject
{
string PathToMonitor=null;

public IFPWatcherComponent(string PathToMonitor)
{

try
{
this.PathToMonitor = PathToMonitor;
//Check to see if Web.config has appropriate settings
if (this.PathToMonitor.Trim().Length==0 ) return;
// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo(this.PathToMonitor);
// Create the directory only if it does not already exist.
if (di.Exists == false)
di.Create();
// create an instance of FileSystemWatcher object and assign path to
monitor
FileSystemWatcher watcher = new FileSystemWatcher();
// set necessary filters
watcher.Path = this.PathToMonitor;
//Watch for changes in FileName
watcher.NotifyFilter = NotifyFilters.FileName;
// watch zip files
watcher.Filter = "*.zip";
//Add appropriate event handler
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.EnableRaisingEvents = true;
}
catch
{
throw;
}
}
private void OnCreated(object source, FileSystemEventArgs e)
{
FileStream oImg=null;
BinaryReader oBinaryReader=null;

Uploader uploader=new Uploader();
uploader.ComeFrom="88";
uploader.Comments="comment";
uploader.CreatedByUser="test";
uploader.FileName=e.Name;

try
{

oImg = new FileStream (e.FullPath,FileMode.Open,FileAccess.Read);
oBinaryReader = new BinaryReader(oImg);
byte[] oImgByteArray = oBinaryReader.ReadBytes((int) oImg.Length);
uploader.FileBody=oImgByteArray;

uploader.RecordType=Business.IFP.RecordType.IFP_UP LOAD;
uploader.Upload();
uploader=null;

}
catch(Exception ee)
{
*******************I don't know how to handle the exception
here??***********************
}
finally
{
if (oBinaryReader!=null) oBinaryReader.Close();
if (oImg!=null) oImg.Close();

}
}

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
Are you sure you are on the right track? A FileSystemWatcher object has
to
exist somewhere to be able to watch. An asp.net application doesn't
exist
anywhere but between a client http request and the server response. A
very
short time. Do you expect the watcher to catch something only when the
server is busy serving client requests?

Eliyahu
"J-T" <Ra****@microsft.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
We are working on an asp.net application which is a 3-tier
application.I
was
aksed to create a component which monitors a folder and gets the file
and
pass them to a class library in our business logic layer(so far so good
and
easy).I initialize my class which is using a FileSystemWatcher in my
Global.asax and everything works fine.I have found FileSystemWatcher
class
not very reliable and sometimes it behavies unexpectedly.I'm afriad
that
it
brings down the whole application.Is there a better way of doing this
**Inside Asp.Net application**.I can't use antother application like
windows
service or schedault taks.Everything needs to be done is ASP.NET
application.
Thanks a lot



Nov 19 '05 #9

P: n/a
J-T
I forgot to say that if I keep my object in an application variable,then the
persistence problem will be solved,right?

Thanks
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u8****************@tk2msftngp13.phx.gbl...
Your FileSystemWatcher is scoped to the method in which you instantiate
it. That means that it goes out of scope and is not available as soon as
the method returns. It may hang around for a bit since you have no code to
dispose it at any point, but you need to bone up on scope and state.
Here's a primer:

Scope is the "area of influence" of a variable. In a class, you have
global and local variables. Global variables are declared outside of any
methods, and are therefore "visible" to all members of the class. Local
variables are declared inside a method, and are therefore "visible" only
to other variables within a single instance (call) of the method. Once the
method returns, it is removed from the stack, and everything in it becomes
available for garbage collection.

Note that this differs from public, private, etc. These are also
definitions of scope, but are more related to encapsulation. Public
members of a class are "visible" from other classes. Private members are
not. Etc.

State refers to the persistence of an object (class instance or primitive)
in memory. Whenever an object is instantiated (created), it must reside in
memory somewhere. The lifetime of an object is limited to the lifetime of
the container in which it resides. A method is instantiated, just like a
variable, whenever you call it. And just like a variable, when it returns,
it is available for garbage collection. The only way to persist an
instance is to put it into something else that persists. Hence, ASP.Net,
which operates using HTTP, which is stateless, has mechanisms for
maintaining state, such as Session, Application, and ViewState.

The global.asax class, as I mentioned in my earlier reply, is a persistent
class, but it's methods are not. They are instantiated like any other
methods, and pass out of scope as soon as they return.

I hope you will study what I've said, and continue to study how OOP works
as you go. In the meantime, you need to understand how to persist your
FileSystemWatcher, as well as making sure that when you are finished with
it, you dispose it.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:e5**************@TK2MSFTNGP14.phx.gbl...
Here is what I have done .I have created a class and I instanciate that
class in Application_Start method of my Global.asax ere is the code:

********Gloabl.asax:
//Sets up a wacher on an specific shared folder to pickup zip files

IFPWatcherComponent ifpWacher=new
IFPWatcherComponent(ConfigurationSettings.AppSetti ngs[ "MonitorPath"]);

********MyClass:

/// </summary>
public class IFPWatcherComponent:BusinessObject
{
string PathToMonitor=null;

public IFPWatcherComponent(string PathToMonitor)
{

try
{
this.PathToMonitor = PathToMonitor;
//Check to see if Web.config has appropriate settings
if (this.PathToMonitor.Trim().Length==0 ) return;
// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo(this.PathToMonitor);
// Create the directory only if it does not already exist.
if (di.Exists == false)
di.Create();
// create an instance of FileSystemWatcher object and assign path to
monitor
FileSystemWatcher watcher = new FileSystemWatcher();
// set necessary filters
watcher.Path = this.PathToMonitor;
//Watch for changes in FileName
watcher.NotifyFilter = NotifyFilters.FileName;
// watch zip files
watcher.Filter = "*.zip";
//Add appropriate event handler
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.EnableRaisingEvents = true;
}
catch
{
throw;
}
}
private void OnCreated(object source, FileSystemEventArgs e)
{
FileStream oImg=null;
BinaryReader oBinaryReader=null;

Uploader uploader=new Uploader();
uploader.ComeFrom="88";
uploader.Comments="comment";
uploader.CreatedByUser="test";
uploader.FileName=e.Name;

try
{

oImg = new FileStream (e.FullPath,FileMode.Open,FileAccess.Read);
oBinaryReader = new BinaryReader(oImg);
byte[] oImgByteArray = oBinaryReader.ReadBytes((int) oImg.Length);
uploader.FileBody=oImgByteArray;

uploader.RecordType=Business.IFP.RecordType.IFP_UP LOAD;
uploader.Upload();
uploader=null;

}
catch(Exception ee)
{
*******************I don't know how to handle the exception
here??***********************
}
finally
{
if (oBinaryReader!=null) oBinaryReader.Close();
if (oImg!=null) oImg.Close();

}
}

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
Are you sure you are on the right track? A FileSystemWatcher object has
to
exist somewhere to be able to watch. An asp.net application doesn't
exist
anywhere but between a client http request and the server response. A
very
short time. Do you expect the watcher to catch something only when the
server is busy serving client requests?

Eliyahu
"J-T" <Ra****@microsft.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
We are working on an asp.net application which is a 3-tier
application.I
was
aksed to create a component which monitors a folder and gets the file
and
pass them to a class library in our business logic layer(so far so good
and
easy).I initialize my class which is using a FileSystemWatcher in my
Global.asax and everything works fine.I have found FileSystemWatcher
class
not very reliable and sometimes it behavies unexpectedly.I'm afriad
that
it
brings down the whole application.Is there a better way of doing this
**Inside Asp.Net application**.I can't use antother application like
windows
service or schedault taks.Everything needs to be done is ASP.NET
application.
Thanks a lot



Nov 19 '05 #10

P: n/a
Even if you persist an object in the application, how can you make sure the
application is running? Did you consider windows service?

Eliyahu

"J-T" <Ra****@microsft.com> wrote in message
news:Oy**************@TK2MSFTNGP12.phx.gbl...
So you mean state wise and persistence wise,both,I will have problems by
using this code?

Do you have any idea how to persist my object.I want it to avaialable as
long as they application is up and working.So according to what you suggest I will have to make the scope of my object some how global (not like the way it is now) and also persist it in the memory for the time application is up. Do I really have to dispose the object after the application gets stopped?

Thanks for super informative answer.

Ray
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u8****************@tk2msftngp13.phx.gbl...
Your FileSystemWatcher is scoped to the method in which you instantiate
it. That means that it goes out of scope and is not available as soon as
the method returns. It may hang around for a bit since you have no code to dispose it at any point, but you need to bone up on scope and state.
Here's a primer:

Scope is the "area of influence" of a variable. In a class, you have
global and local variables. Global variables are declared outside of any
methods, and are therefore "visible" to all members of the class. Local
variables are declared inside a method, and are therefore "visible" only
to other variables within a single instance (call) of the method. Once the method returns, it is removed from the stack, and everything in it becomes available for garbage collection.

Note that this differs from public, private, etc. These are also
definitions of scope, but are more related to encapsulation. Public
members of a class are "visible" from other classes. Private members are
not. Etc.

State refers to the persistence of an object (class instance or primitive) in memory. Whenever an object is instantiated (created), it must reside in memory somewhere. The lifetime of an object is limited to the lifetime of the container in which it resides. A method is instantiated, just like a
variable, whenever you call it. And just like a variable, when it returns, it is available for garbage collection. The only way to persist an
instance is to put it into something else that persists. Hence, ASP.Net,
which operates using HTTP, which is stateless, has mechanisms for
maintaining state, such as Session, Application, and ViewState.

The global.asax class, as I mentioned in my earlier reply, is a persistent class, but it's methods are not. They are instantiated like any other
methods, and pass out of scope as soon as they return.

I hope you will study what I've said, and continue to study how OOP works as you go. In the meantime, you need to understand how to persist your
FileSystemWatcher, as well as making sure that when you are finished with it, you dispose it.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:e5**************@TK2MSFTNGP14.phx.gbl...
Here is what I have done .I have created a class and I instanciate that
class in Application_Start method of my Global.asax ere is the code:

********Gloabl.asax:
//Sets up a wacher on an specific shared folder to pickup zip files

IFPWatcherComponent ifpWacher=new
IFPWatcherComponent(ConfigurationSettings.AppSetti ngs[ "MonitorPath"]);

********MyClass:

/// </summary>
public class IFPWatcherComponent:BusinessObject
{
string PathToMonitor=null;

public IFPWatcherComponent(string PathToMonitor)
{

try
{
this.PathToMonitor = PathToMonitor;
//Check to see if Web.config has appropriate settings
if (this.PathToMonitor.Trim().Length==0 ) return;
// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo(this.PathToMonitor);
// Create the directory only if it does not already exist.
if (di.Exists == false)
di.Create();
// create an instance of FileSystemWatcher object and assign path to
monitor
FileSystemWatcher watcher = new FileSystemWatcher();
// set necessary filters
watcher.Path = this.PathToMonitor;
//Watch for changes in FileName
watcher.NotifyFilter = NotifyFilters.FileName;
// watch zip files
watcher.Filter = "*.zip";
//Add appropriate event handler
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.EnableRaisingEvents = true;
}
catch
{
throw;
}
}
private void OnCreated(object source, FileSystemEventArgs e)
{
FileStream oImg=null;
BinaryReader oBinaryReader=null;

Uploader uploader=new Uploader();
uploader.ComeFrom="88";
uploader.Comments="comment";
uploader.CreatedByUser="test";
uploader.FileName=e.Name;

try
{

oImg = new FileStream (e.FullPath,FileMode.Open,FileAccess.Read);
oBinaryReader = new BinaryReader(oImg);
byte[] oImgByteArray = oBinaryReader.ReadBytes((int) oImg.Length);
uploader.FileBody=oImgByteArray;

uploader.RecordType=Business.IFP.RecordType.IFP_UP LOAD;
uploader.Upload();
uploader=null;

}
catch(Exception ee)
{
*******************I don't know how to handle the exception
here??***********************
}
finally
{
if (oBinaryReader!=null) oBinaryReader.Close();
if (oImg!=null) oImg.Close();

}
}

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
Are you sure you are on the right track? A FileSystemWatcher object has to
exist somewhere to be able to watch. An asp.net application doesn't
exist
anywhere but between a client http request and the server response. A
very
short time. Do you expect the watcher to catch something only when the
server is busy serving client requests?

Eliyahu
"J-T" <Ra****@microsft.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
> We are working on an asp.net application which is a 3-tier
> application.I
was
> aksed to create a component which monitors a folder and gets the file
> and
> pass them to a class library in our business logic layer(so far so good and
> easy).I initialize my class which is using a FileSystemWatcher in my
> Global.asax and everything works fine.I have found FileSystemWatcher
class
> not very reliable and sometimes it behavies unexpectedly.I'm afriad
> that
it
> brings down the whole application.Is there a better way of doing this
> **Inside Asp.Net application**.I can't use antother application like
windows
> service or schedault taks.Everything needs to be done is ASP.NET
> application.
>
>
> Thanks a lot
>
>



Nov 19 '05 #11

P: n/a
You can set up a scheduled task that will copy files over to a local
directory periodically. Not very elegant, but works.

Eliyahu

"J-T" <Ra****@microsft.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
So how would you monitor a network path in your asp.net application?
Thanks for your reply.
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:e7**************@TK2MSFTNGP12.phx.gbl...
This could be a problem. In my experience I could not get
FileSystemWatcher
to work for network directories. Either it is not able to or some tricky
setting is needed.

Eliyahu

"J-T" <Ra****@microsft.com> wrote in message
news:Ov**************@tk2msftngp13.phx.gbl...
I forgot to say that directory which I monitor is a shared folder on the netwrok.

Thanks
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
> Are you sure you are on the right track? A FileSystemWatcher object has
to
> exist somewhere to be able to watch. An asp.net application doesn't

exist
> anywhere but between a client http request and the server response. A

very
> short time. Do you expect the watcher to catch something only when
the > server is busy serving client requests?
>
> Eliyahu
>
>
> "J-T" <Ra****@microsft.com> wrote in message
> news:%2****************@TK2MSFTNGP15.phx.gbl...
>> We are working on an asp.net application which is a 3-tier

application.I
> was
>> aksed to create a component which monitors a folder and gets the file and
>> pass them to a class library in our business logic layer(so far so
>> good
> and
>> easy).I initialize my class which is using a FileSystemWatcher in my
>> Global.asax and everything works fine.I have found

FileSystemWatcher > class
>> not very reliable and sometimes it behavies unexpectedly.I'm afriad

that
> it
>> brings down the whole application.Is there a better way of doing this >> **Inside Asp.Net application**.I can't use antother application like
> windows
>> service or schedault taks.Everything needs to be done is ASP.NET
>> application.
>>
>>
>> Thanks a lot
>>
>>
>
>



Nov 19 '05 #12

P: n/a
>I forgot to say that if I keep my object in an application variable,then
the persistence problem will be solved,right?
Yes. However, be aware that an ASP.Net application will stop running when it
is idle (no requests) for a period of more than (by default) 20 minutes.
When the application is stopped, the FileSystemWatcher will be stopped. When
the application restarts, the FileSystemWatcher will be restarted as well.
HOWEVER, any changes to the file system that the Watcher is supposed to
watch during the idle interval will go unnoticed. Now, as long as changes to
the files in the folder are also done by the ASP.Net app, there will BE no
changes while the app is stopped. So, while I can't answer your question
directly, this information, plus what you already know, should give you the
solution you need.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:eJ***************@TK2MSFTNGP12.phx.gbl...I forgot to say that if I keep my object in an application variable,then
the persistence problem will be solved,right?

Thanks
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u8****************@tk2msftngp13.phx.gbl...
Your FileSystemWatcher is scoped to the method in which you instantiate
it. That means that it goes out of scope and is not available as soon as
the method returns. It may hang around for a bit since you have no code
to dispose it at any point, but you need to bone up on scope and state.
Here's a primer:

Scope is the "area of influence" of a variable. In a class, you have
global and local variables. Global variables are declared outside of any
methods, and are therefore "visible" to all members of the class. Local
variables are declared inside a method, and are therefore "visible" only
to other variables within a single instance (call) of the method. Once
the method returns, it is removed from the stack, and everything in it
becomes available for garbage collection.

Note that this differs from public, private, etc. These are also
definitions of scope, but are more related to encapsulation. Public
members of a class are "visible" from other classes. Private members are
not. Etc.

State refers to the persistence of an object (class instance or
primitive) in memory. Whenever an object is instantiated (created), it
must reside in memory somewhere. The lifetime of an object is limited to
the lifetime of the container in which it resides. A method is
instantiated, just like a variable, whenever you call it. And just like a
variable, when it returns, it is available for garbage collection. The
only way to persist an instance is to put it into something else that
persists. Hence, ASP.Net, which operates using HTTP, which is stateless,
has mechanisms for maintaining state, such as Session, Application, and
ViewState.

The global.asax class, as I mentioned in my earlier reply, is a
persistent class, but it's methods are not. They are instantiated like
any other methods, and pass out of scope as soon as they return.

I hope you will study what I've said, and continue to study how OOP works
as you go. In the meantime, you need to understand how to persist your
FileSystemWatcher, as well as making sure that when you are finished with
it, you dispose it.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:e5**************@TK2MSFTNGP14.phx.gbl...
Here is what I have done .I have created a class and I instanciate that
class in Application_Start method of my Global.asax ere is the code:

********Gloabl.asax:
//Sets up a wacher on an specific shared folder to pickup zip files

IFPWatcherComponent ifpWacher=new
IFPWatcherComponent(ConfigurationSettings.AppSetti ngs[ "MonitorPath"]);

********MyClass:

/// </summary>
public class IFPWatcherComponent:BusinessObject
{
string PathToMonitor=null;

public IFPWatcherComponent(string PathToMonitor)
{

try
{
this.PathToMonitor = PathToMonitor;
//Check to see if Web.config has appropriate settings
if (this.PathToMonitor.Trim().Length==0 ) return;
// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo(this.PathToMonitor);
// Create the directory only if it does not already exist.
if (di.Exists == false)
di.Create();
// create an instance of FileSystemWatcher object and assign path to
monitor
FileSystemWatcher watcher = new FileSystemWatcher();
// set necessary filters
watcher.Path = this.PathToMonitor;
//Watch for changes in FileName
watcher.NotifyFilter = NotifyFilters.FileName;
// watch zip files
watcher.Filter = "*.zip";
//Add appropriate event handler
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.EnableRaisingEvents = true;
}
catch
{
throw;
}
}
private void OnCreated(object source, FileSystemEventArgs e)
{
FileStream oImg=null;
BinaryReader oBinaryReader=null;

Uploader uploader=new Uploader();
uploader.ComeFrom="88";
uploader.Comments="comment";
uploader.CreatedByUser="test";
uploader.FileName=e.Name;

try
{

oImg = new FileStream (e.FullPath,FileMode.Open,FileAccess.Read);
oBinaryReader = new BinaryReader(oImg);
byte[] oImgByteArray = oBinaryReader.ReadBytes((int) oImg.Length);
uploader.FileBody=oImgByteArray;

uploader.RecordType=Business.IFP.RecordType.IFP_UP LOAD;
uploader.Upload();
uploader=null;

}
catch(Exception ee)
{
*******************I don't know how to handle the exception
here??***********************
}
finally
{
if (oBinaryReader!=null) oBinaryReader.Close();
if (oImg!=null) oImg.Close();

}
}

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
Are you sure you are on the right track? A FileSystemWatcher object has
to
exist somewhere to be able to watch. An asp.net application doesn't
exist
anywhere but between a client http request and the server response. A
very
short time. Do you expect the watcher to catch something only when the
server is busy serving client requests?

Eliyahu
"J-T" <Ra****@microsft.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
> We are working on an asp.net application which is a 3-tier
> application.I
was
> aksed to create a component which monitors a folder and gets the file
> and
> pass them to a class library in our business logic layer(so far so
> good
and
> easy).I initialize my class which is using a FileSystemWatcher in my
> Global.asax and everything works fine.I have found FileSystemWatcher
class
> not very reliable and sometimes it behavies unexpectedly.I'm afriad
> that
it
> brings down the whole application.Is there a better way of doing this
> **Inside Asp.Net application**.I can't use antother application like
windows
> service or schedault taks.Everything needs to be done is ASP.NET
> application.
>
>
> Thanks a lot
>
>



Nov 19 '05 #13

P: n/a
How about this :

Make my object remotly callable and register an sponser in the same
machine(Webserver) to call my object when it is going to be leased?

Makes sense?

Thanks for your help.

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
I forgot to say that if I keep my object in an application variable,then
the persistence problem will be solved,right?


Yes. However, be aware that an ASP.Net application will stop running when
it is idle (no requests) for a period of more than (by default) 20
minutes. When the application is stopped, the FileSystemWatcher will be
stopped. When the application restarts, the FileSystemWatcher will be
restarted as well. HOWEVER, any changes to the file system that the
Watcher is supposed to watch during the idle interval will go unnoticed.
Now, as long as changes to the files in the folder are also done by the
ASP.Net app, there will BE no changes while the app is stopped. So, while
I can't answer your question directly, this information, plus what you
already know, should give you the solution you need.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:eJ***************@TK2MSFTNGP12.phx.gbl...
I forgot to say that if I keep my object in an application variable,then
the persistence problem will be solved,right?

Thanks
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u8****************@tk2msftngp13.phx.gbl...
Your FileSystemWatcher is scoped to the method in which you instantiate
it. That means that it goes out of scope and is not available as soon as
the method returns. It may hang around for a bit since you have no code
to dispose it at any point, but you need to bone up on scope and state.
Here's a primer:

Scope is the "area of influence" of a variable. In a class, you have
global and local variables. Global variables are declared outside of any
methods, and are therefore "visible" to all members of the class. Local
variables are declared inside a method, and are therefore "visible" only
to other variables within a single instance (call) of the method. Once
the method returns, it is removed from the stack, and everything in it
becomes available for garbage collection.

Note that this differs from public, private, etc. These are also
definitions of scope, but are more related to encapsulation. Public
members of a class are "visible" from other classes. Private members are
not. Etc.

State refers to the persistence of an object (class instance or
primitive) in memory. Whenever an object is instantiated (created), it
must reside in memory somewhere. The lifetime of an object is limited to
the lifetime of the container in which it resides. A method is
instantiated, just like a variable, whenever you call it. And just like
a variable, when it returns, it is available for garbage collection. The
only way to persist an instance is to put it into something else that
persists. Hence, ASP.Net, which operates using HTTP, which is stateless,
has mechanisms for maintaining state, such as Session, Application, and
ViewState.

The global.asax class, as I mentioned in my earlier reply, is a
persistent class, but it's methods are not. They are instantiated like
any other methods, and pass out of scope as soon as they return.

I hope you will study what I've said, and continue to study how OOP
works as you go. In the meantime, you need to understand how to persist
your FileSystemWatcher, as well as making sure that when you are
finished with it, you dispose it.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:e5**************@TK2MSFTNGP14.phx.gbl...
Here is what I have done .I have created a class and I instanciate that
class in Application_Start method of my Global.asax ere is the code:

********Gloabl.asax:
//Sets up a wacher on an specific shared folder to pickup zip files

IFPWatcherComponent ifpWacher=new
IFPWatcherComponent(ConfigurationSettings.AppSetti ngs[ "MonitorPath"]);

********MyClass:

/// </summary>
public class IFPWatcherComponent:BusinessObject
{
string PathToMonitor=null;

public IFPWatcherComponent(string PathToMonitor)
{

try
{
this.PathToMonitor = PathToMonitor;
//Check to see if Web.config has appropriate settings
if (this.PathToMonitor.Trim().Length==0 ) return;
// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo(this.PathToMonitor);
// Create the directory only if it does not already exist.
if (di.Exists == false)
di.Create();
// create an instance of FileSystemWatcher object and assign path to
monitor
FileSystemWatcher watcher = new FileSystemWatcher();
// set necessary filters
watcher.Path = this.PathToMonitor;
//Watch for changes in FileName
watcher.NotifyFilter = NotifyFilters.FileName;
// watch zip files
watcher.Filter = "*.zip";
//Add appropriate event handler
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.EnableRaisingEvents = true;
}
catch
{
throw;
}
}
private void OnCreated(object source, FileSystemEventArgs e)
{
FileStream oImg=null;
BinaryReader oBinaryReader=null;

Uploader uploader=new Uploader();
uploader.ComeFrom="88";
uploader.Comments="comment";
uploader.CreatedByUser="test";
uploader.FileName=e.Name;

try
{

oImg = new FileStream (e.FullPath,FileMode.Open,FileAccess.Read);
oBinaryReader = new BinaryReader(oImg);
byte[] oImgByteArray = oBinaryReader.ReadBytes((int) oImg.Length);
uploader.FileBody=oImgByteArray;

uploader.RecordType=Business.IFP.RecordType.IFP_UP LOAD;
uploader.Upload();
uploader=null;

}
catch(Exception ee)
{
*******************I don't know how to handle the exception
here??***********************
}
finally
{
if (oBinaryReader!=null) oBinaryReader.Close();
if (oImg!=null) oImg.Close();

}
}

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
> Are you sure you are on the right track? A FileSystemWatcher object
> has to
> exist somewhere to be able to watch. An asp.net application doesn't
> exist
> anywhere but between a client http request and the server response. A
> very
> short time. Do you expect the watcher to catch something only when the
> server is busy serving client requests?
>
> Eliyahu
>
>
> "J-T" <Ra****@microsft.com> wrote in message
> news:%2****************@TK2MSFTNGP15.phx.gbl...
>> We are working on an asp.net application which is a 3-tier
>> application.I
> was
>> aksed to create a component which monitors a folder and gets the file
>> and
>> pass them to a class library in our business logic layer(so far so
>> good
> and
>> easy).I initialize my class which is using a FileSystemWatcher in my
>> Global.asax and everything works fine.I have found FileSystemWatcher
> class
>> not very reliable and sometimes it behavies unexpectedly.I'm afriad
>> that
> it
>> brings down the whole application.Is there a better way of doing this
>> **Inside Asp.Net application**.I can't use antother application like
> windows
>> service or schedault taks.Everything needs to be done is ASP.NET
>> application.
>>
>>
>> Thanks a lot
>>
>>
>
>



Nov 19 '05 #14

P: n/a
The reason I'm bearing with all these problems is that I don;t want to use a
seperate component outside of our asp.net application.What do you mean by
using a windows service? you mean using windows service to keep the object
alive ? kind of sponser thing in remoting?

Thanks
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:Oy**************@TK2MSFTNGP14.phx.gbl...
Even if you persist an object in the application, how can you make sure
the
application is running? Did you consider windows service?

Eliyahu

"J-T" <Ra****@microsft.com> wrote in message
news:Oy**************@TK2MSFTNGP12.phx.gbl...
So you mean state wise and persistence wise,both,I will have problems by
using this code?

Do you have any idea how to persist my object.I want it to avaialable as
long as they application is up and working.So according to what you

suggest
I will have to make the scope of my object some how global (not like the

way
it is now) and also persist it in the memory for the time application is

up.
Do I really have to dispose the object after the application gets
stopped?

Thanks for super informative answer.

Ray
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u8****************@tk2msftngp13.phx.gbl...
> Your FileSystemWatcher is scoped to the method in which you instantiate
> it. That means that it goes out of scope and is not available as soon
> as
> the method returns. It may hang around for a bit since you have no code to > dispose it at any point, but you need to bone up on scope and state.
> Here's a primer:
>
> Scope is the "area of influence" of a variable. In a class, you have
> global and local variables. Global variables are declared outside of
> any
> methods, and are therefore "visible" to all members of the class. Local
> variables are declared inside a method, and are therefore "visible"
> only
> to other variables within a single instance (call) of the method. Once the > method returns, it is removed from the stack, and everything in it becomes > available for garbage collection.
>
> Note that this differs from public, private, etc. These are also
> definitions of scope, but are more related to encapsulation. Public
> members of a class are "visible" from other classes. Private members
> are
> not. Etc.
>
> State refers to the persistence of an object (class instance or primitive) > in memory. Whenever an object is instantiated (created), it must reside in > memory somewhere. The lifetime of an object is limited to the lifetime of > the container in which it resides. A method is instantiated, just like
> a
> variable, whenever you call it. And just like a variable, when it returns, > it is available for garbage collection. The only way to persist an
> instance is to put it into something else that persists. Hence,
> ASP.Net,
> which operates using HTTP, which is stateless, has mechanisms for
> maintaining state, such as Session, Application, and ViewState.
>
> The global.asax class, as I mentioned in my earlier reply, is a persistent > class, but it's methods are not. They are instantiated like any other
> methods, and pass out of scope as soon as they return.
>
> I hope you will study what I've said, and continue to study how OOP works > as you go. In the meantime, you need to understand how to persist your
> FileSystemWatcher, as well as making sure that when you are finished with > it, you dispose it.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> Sometimes you eat the elephant.
> Sometimes the elephant eats you.
>
> "J-T" <Ra****@microsft.com> wrote in message
> news:e5**************@TK2MSFTNGP14.phx.gbl...
>> Here is what I have done .I have created a class and I instanciate
>> that
>> class in Application_Start method of my Global.asax ere is the code:
>>
>> ********Gloabl.asax:
>> //Sets up a wacher on an specific shared folder to pickup zip files
>>
>> IFPWatcherComponent ifpWacher=new
>> IFPWatcherComponent(ConfigurationSettings.AppSetti ngs[
>> "MonitorPath"]);
>>
>>
>>
>> ********MyClass:
>>
>> /// </summary>
>> public class IFPWatcherComponent:BusinessObject
>> {
>> string PathToMonitor=null;
>>
>> public IFPWatcherComponent(string PathToMonitor)
>> {
>>
>> try
>> {
>> this.PathToMonitor = PathToMonitor;
>> //Check to see if Web.config has appropriate settings
>> if (this.PathToMonitor.Trim().Length==0 ) return;
>> // Make a reference to a directory.
>> DirectoryInfo di = new DirectoryInfo(this.PathToMonitor);
>> // Create the directory only if it does not already exist.
>> if (di.Exists == false)
>> di.Create();
>> // create an instance of FileSystemWatcher object and assign path
>> to
>> monitor
>> FileSystemWatcher watcher = new FileSystemWatcher();
>> // set necessary filters
>> watcher.Path = this.PathToMonitor;
>> //Watch for changes in FileName
>> watcher.NotifyFilter = NotifyFilters.FileName;
>> // watch zip files
>> watcher.Filter = "*.zip";
>> //Add appropriate event handler
>> watcher.Created += new FileSystemEventHandler(OnCreated);
>> watcher.EnableRaisingEvents = true;
>> }
>> catch
>> {
>> throw;
>> }
>> }
>> private void OnCreated(object source, FileSystemEventArgs e)
>> {
>> FileStream oImg=null;
>> BinaryReader oBinaryReader=null;
>>
>> Uploader uploader=new Uploader();
>> uploader.ComeFrom="88";
>> uploader.Comments="comment";
>> uploader.CreatedByUser="test";
>> uploader.FileName=e.Name;
>>
>> try
>> {
>>
>> oImg = new FileStream (e.FullPath,FileMode.Open,FileAccess.Read);
>> oBinaryReader = new BinaryReader(oImg);
>> byte[] oImgByteArray = oBinaryReader.ReadBytes((int) oImg.Length);
>> uploader.FileBody=oImgByteArray;
>>
>> uploader.RecordType=Business.IFP.RecordType.IFP_UP LOAD;
>> uploader.Upload();
>> uploader=null;
>>
>> }
>> catch(Exception ee)
>> {
>> *******************I don't know how to handle the exception
>> here??***********************
>> }
>> finally
>> {
>> if (oBinaryReader!=null) oBinaryReader.Close();
>> if (oImg!=null) oImg.Close();
>>
>> }
>> }
>>
>> "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
>> news:ud**************@TK2MSFTNGP09.phx.gbl...
>>> Are you sure you are on the right track? A FileSystemWatcher object has >>> to
>>> exist somewhere to be able to watch. An asp.net application doesn't
>>> exist
>>> anywhere but between a client http request and the server response. A
>>> very
>>> short time. Do you expect the watcher to catch something only when
>>> the
>>> server is busy serving client requests?
>>>
>>> Eliyahu
>>>
>>>
>>> "J-T" <Ra****@microsft.com> wrote in message
>>> news:%2****************@TK2MSFTNGP15.phx.gbl...
>>>> We are working on an asp.net application which is a 3-tier
>>>> application.I
>>> was
>>>> aksed to create a component which monitors a folder and gets the
>>>> file
>>>> and
>>>> pass them to a class library in our business logic layer(so far so good >>> and
>>>> easy).I initialize my class which is using a FileSystemWatcher in my
>>>> Global.asax and everything works fine.I have found
>>>> FileSystemWatcher
>>> class
>>>> not very reliable and sometimes it behavies unexpectedly.I'm afriad
>>>> that
>>> it
>>>> brings down the whole application.Is there a better way of doing
>>>> this
>>>> **Inside Asp.Net application**.I can't use antother application like
>>> windows
>>>> service or schedault taks.Everything needs to be done is ASP.NET
>>>> application.
>>>>
>>>>
>>>> Thanks a lot
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Nov 19 '05 #15

P: n/a
You can't remotely call an object. An object is a type, just like an
Integer, or a Function. It exists only as an instance inside an application.
So, you have to write a service if you want it to run all the time. You
COULD keep your ASP.Net Application alive by making Requests to the app
shortly before the Application Timeout, but that would require a client
application to be running all the time.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"Ray5531" <Ra****@microsft.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
How about this :

Make my object remotly callable and register an sponser in the same
machine(Webserver) to call my object when it is going to be leased?

Makes sense?

Thanks for your help.

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
>I forgot to say that if I keep my object in an application variable,then
>the persistence problem will be solved,right?


Yes. However, be aware that an ASP.Net application will stop running when
it is idle (no requests) for a period of more than (by default) 20
minutes. When the application is stopped, the FileSystemWatcher will be
stopped. When the application restarts, the FileSystemWatcher will be
restarted as well. HOWEVER, any changes to the file system that the
Watcher is supposed to watch during the idle interval will go unnoticed.
Now, as long as changes to the files in the folder are also done by the
ASP.Net app, there will BE no changes while the app is stopped. So, while
I can't answer your question directly, this information, plus what you
already know, should give you the solution you need.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:eJ***************@TK2MSFTNGP12.phx.gbl...
I forgot to say that if I keep my object in an application variable,then
the persistence problem will be solved,right?

Thanks
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u8****************@tk2msftngp13.phx.gbl...
Your FileSystemWatcher is scoped to the method in which you instantiate
it. That means that it goes out of scope and is not available as soon
as the method returns. It may hang around for a bit since you have no
code to dispose it at any point, but you need to bone up on scope and
state. Here's a primer:

Scope is the "area of influence" of a variable. In a class, you have
global and local variables. Global variables are declared outside of
any methods, and are therefore "visible" to all members of the class.
Local variables are declared inside a method, and are therefore
"visible" only to other variables within a single instance (call) of
the method. Once the method returns, it is removed from the stack, and
everything in it becomes available for garbage collection.

Note that this differs from public, private, etc. These are also
definitions of scope, but are more related to encapsulation. Public
members of a class are "visible" from other classes. Private members
are not. Etc.

State refers to the persistence of an object (class instance or
primitive) in memory. Whenever an object is instantiated (created), it
must reside in memory somewhere. The lifetime of an object is limited
to the lifetime of the container in which it resides. A method is
instantiated, just like a variable, whenever you call it. And just like
a variable, when it returns, it is available for garbage collection.
The only way to persist an instance is to put it into something else
that persists. Hence, ASP.Net, which operates using HTTP, which is
stateless, has mechanisms for maintaining state, such as Session,
Application, and ViewState.

The global.asax class, as I mentioned in my earlier reply, is a
persistent class, but it's methods are not. They are instantiated like
any other methods, and pass out of scope as soon as they return.

I hope you will study what I've said, and continue to study how OOP
works as you go. In the meantime, you need to understand how to persist
your FileSystemWatcher, as well as making sure that when you are
finished with it, you dispose it.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:e5**************@TK2MSFTNGP14.phx.gbl...
> Here is what I have done .I have created a class and I instanciate
> that class in Application_Start method of my Global.asax ere is the
> code:
>
> ********Gloabl.asax:
> //Sets up a wacher on an specific shared folder to pickup zip files
>
> IFPWatcherComponent ifpWacher=new
> IFPWatcherComponent(ConfigurationSettings.AppSetti ngs[
> "MonitorPath"]);
>
>
>
> ********MyClass:
>
> /// </summary>
> public class IFPWatcherComponent:BusinessObject
> {
> string PathToMonitor=null;
>
> public IFPWatcherComponent(string PathToMonitor)
> {
>
> try
> {
> this.PathToMonitor = PathToMonitor;
> //Check to see if Web.config has appropriate settings
> if (this.PathToMonitor.Trim().Length==0 ) return;
> // Make a reference to a directory.
> DirectoryInfo di = new DirectoryInfo(this.PathToMonitor);
> // Create the directory only if it does not already exist.
> if (di.Exists == false)
> di.Create();
> // create an instance of FileSystemWatcher object and assign path
> to monitor
> FileSystemWatcher watcher = new FileSystemWatcher();
> // set necessary filters
> watcher.Path = this.PathToMonitor;
> //Watch for changes in FileName
> watcher.NotifyFilter = NotifyFilters.FileName;
> // watch zip files
> watcher.Filter = "*.zip";
> //Add appropriate event handler
> watcher.Created += new FileSystemEventHandler(OnCreated);
> watcher.EnableRaisingEvents = true;
> }
> catch
> {
> throw;
> }
> }
> private void OnCreated(object source, FileSystemEventArgs e)
> {
> FileStream oImg=null;
> BinaryReader oBinaryReader=null;
>
> Uploader uploader=new Uploader();
> uploader.ComeFrom="88";
> uploader.Comments="comment";
> uploader.CreatedByUser="test";
> uploader.FileName=e.Name;
>
> try
> {
>
> oImg = new FileStream (e.FullPath,FileMode.Open,FileAccess.Read);
> oBinaryReader = new BinaryReader(oImg);
> byte[] oImgByteArray = oBinaryReader.ReadBytes((int) oImg.Length);
> uploader.FileBody=oImgByteArray;
>
> uploader.RecordType=Business.IFP.RecordType.IFP_UP LOAD;
> uploader.Upload();
> uploader=null;
>
> }
> catch(Exception ee)
> {
> *******************I don't know how to handle the exception
> here??***********************
> }
> finally
> {
> if (oBinaryReader!=null) oBinaryReader.Close();
> if (oImg!=null) oImg.Close();
>
> }
> }
>
> "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
> news:ud**************@TK2MSFTNGP09.phx.gbl...
>> Are you sure you are on the right track? A FileSystemWatcher object
>> has to
>> exist somewhere to be able to watch. An asp.net application doesn't
>> exist
>> anywhere but between a client http request and the server response. A
>> very
>> short time. Do you expect the watcher to catch something only when
>> the
>> server is busy serving client requests?
>>
>> Eliyahu
>>
>>
>> "J-T" <Ra****@microsft.com> wrote in message
>> news:%2****************@TK2MSFTNGP15.phx.gbl...
>>> We are working on an asp.net application which is a 3-tier
>>> application.I
>> was
>>> aksed to create a component which monitors a folder and gets the
>>> file and
>>> pass them to a class library in our business logic layer(so far so
>>> good
>> and
>>> easy).I initialize my class which is using a FileSystemWatcher in my
>>> Global.asax and everything works fine.I have found
>>> FileSystemWatcher
>> class
>>> not very reliable and sometimes it behavies unexpectedly.I'm afriad
>>> that
>> it
>>> brings down the whole application.Is there a better way of doing
>>> this
>>> **Inside Asp.Net application**.I can't use antother application like
>> windows
>>> service or schedault taks.Everything needs to be done is ASP.NET
>>> application.
>>>
>>>
>>> Thanks a lot
>>>
>>>
>>
>>
>
>



Nov 19 '05 #16

P: n/a
Or how about this:

OnCreate event of the file ,I query the directory for all the files of the
type of I want and loop through them and enforce what I want.In the way even
if the application is in idle mode and filesystemWatcher is down as well,the
next file which triggers the fileSystemWatcher causes all the other files to
be processed as well.

Thanks
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
I forgot to say that if I keep my object in an application variable,then
the persistence problem will be solved,right?


Yes. However, be aware that an ASP.Net application will stop running when
it is idle (no requests) for a period of more than (by default) 20
minutes. When the application is stopped, the FileSystemWatcher will be
stopped. When the application restarts, the FileSystemWatcher will be
restarted as well. HOWEVER, any changes to the file system that the
Watcher is supposed to watch during the idle interval will go unnoticed.
Now, as long as changes to the files in the folder are also done by the
ASP.Net app, there will BE no changes while the app is stopped. So, while
I can't answer your question directly, this information, plus what you
already know, should give you the solution you need.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:eJ***************@TK2MSFTNGP12.phx.gbl...
I forgot to say that if I keep my object in an application variable,then
the persistence problem will be solved,right?

Thanks
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u8****************@tk2msftngp13.phx.gbl...
Your FileSystemWatcher is scoped to the method in which you instantiate
it. That means that it goes out of scope and is not available as soon as
the method returns. It may hang around for a bit since you have no code
to dispose it at any point, but you need to bone up on scope and state.
Here's a primer:

Scope is the "area of influence" of a variable. In a class, you have
global and local variables. Global variables are declared outside of any
methods, and are therefore "visible" to all members of the class. Local
variables are declared inside a method, and are therefore "visible" only
to other variables within a single instance (call) of the method. Once
the method returns, it is removed from the stack, and everything in it
becomes available for garbage collection.

Note that this differs from public, private, etc. These are also
definitions of scope, but are more related to encapsulation. Public
members of a class are "visible" from other classes. Private members are
not. Etc.

State refers to the persistence of an object (class instance or
primitive) in memory. Whenever an object is instantiated (created), it
must reside in memory somewhere. The lifetime of an object is limited to
the lifetime of the container in which it resides. A method is
instantiated, just like a variable, whenever you call it. And just like
a variable, when it returns, it is available for garbage collection. The
only way to persist an instance is to put it into something else that
persists. Hence, ASP.Net, which operates using HTTP, which is stateless,
has mechanisms for maintaining state, such as Session, Application, and
ViewState.

The global.asax class, as I mentioned in my earlier reply, is a
persistent class, but it's methods are not. They are instantiated like
any other methods, and pass out of scope as soon as they return.

I hope you will study what I've said, and continue to study how OOP
works as you go. In the meantime, you need to understand how to persist
your FileSystemWatcher, as well as making sure that when you are
finished with it, you dispose it.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:e5**************@TK2MSFTNGP14.phx.gbl...
Here is what I have done .I have created a class and I instanciate that
class in Application_Start method of my Global.asax ere is the code:

********Gloabl.asax:
//Sets up a wacher on an specific shared folder to pickup zip files

IFPWatcherComponent ifpWacher=new
IFPWatcherComponent(ConfigurationSettings.AppSetti ngs[ "MonitorPath"]);

********MyClass:

/// </summary>
public class IFPWatcherComponent:BusinessObject
{
string PathToMonitor=null;

public IFPWatcherComponent(string PathToMonitor)
{

try
{
this.PathToMonitor = PathToMonitor;
//Check to see if Web.config has appropriate settings
if (this.PathToMonitor.Trim().Length==0 ) return;
// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo(this.PathToMonitor);
// Create the directory only if it does not already exist.
if (di.Exists == false)
di.Create();
// create an instance of FileSystemWatcher object and assign path to
monitor
FileSystemWatcher watcher = new FileSystemWatcher();
// set necessary filters
watcher.Path = this.PathToMonitor;
//Watch for changes in FileName
watcher.NotifyFilter = NotifyFilters.FileName;
// watch zip files
watcher.Filter = "*.zip";
//Add appropriate event handler
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.EnableRaisingEvents = true;
}
catch
{
throw;
}
}
private void OnCreated(object source, FileSystemEventArgs e)
{
FileStream oImg=null;
BinaryReader oBinaryReader=null;

Uploader uploader=new Uploader();
uploader.ComeFrom="88";
uploader.Comments="comment";
uploader.CreatedByUser="test";
uploader.FileName=e.Name;

try
{

oImg = new FileStream (e.FullPath,FileMode.Open,FileAccess.Read);
oBinaryReader = new BinaryReader(oImg);
byte[] oImgByteArray = oBinaryReader.ReadBytes((int) oImg.Length);
uploader.FileBody=oImgByteArray;

uploader.RecordType=Business.IFP.RecordType.IFP_UP LOAD;
uploader.Upload();
uploader=null;

}
catch(Exception ee)
{
*******************I don't know how to handle the exception
here??***********************
}
finally
{
if (oBinaryReader!=null) oBinaryReader.Close();
if (oImg!=null) oImg.Close();

}
}

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
> Are you sure you are on the right track? A FileSystemWatcher object
> has to
> exist somewhere to be able to watch. An asp.net application doesn't
> exist
> anywhere but between a client http request and the server response. A
> very
> short time. Do you expect the watcher to catch something only when the
> server is busy serving client requests?
>
> Eliyahu
>
>
> "J-T" <Ra****@microsft.com> wrote in message
> news:%2****************@TK2MSFTNGP15.phx.gbl...
>> We are working on an asp.net application which is a 3-tier
>> application.I
> was
>> aksed to create a component which monitors a folder and gets the file
>> and
>> pass them to a class library in our business logic layer(so far so
>> good
> and
>> easy).I initialize my class which is using a FileSystemWatcher in my
>> Global.asax and everything works fine.I have found FileSystemWatcher
> class
>> not very reliable and sometimes it behavies unexpectedly.I'm afriad
>> that
> it
>> brings down the whole application.Is there a better way of doing this
>> **Inside Asp.Net application**.I can't use antother application like
> windows
>> service or schedault taks.Everything needs to be done is ASP.NET
>> application.
>>
>>
>> Thanks a lot
>>
>>
>
>



Nov 19 '05 #17

P: n/a
> Or how about this:

OnCreate event of the file ,I query the directory for all the files of the
type of I want and loop through them and enforce what I want.In the way
even if the application is in idle mode and filesystemWatcher is down as
well,the next file which triggers the fileSystemWatcher causes all the
other files to be processed as well.
If you're going to do that, you don't need anything right away, right? In
that case, you don't need a FileSystemWatcher at all, just a timer and
System.IO to check and keep track of the contents of the folder. Problem
solved, at least if you don't need the data immediately.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"Ray5531" <Ra****@microsft.com> wrote in message
news:OV**************@TK2MSFTNGP14.phx.gbl... Or how about this:

OnCreate event of the file ,I query the directory for all the files of the
type of I want and loop through them and enforce what I want.In the way
even if the application is in idle mode and filesystemWatcher is down as
well,the next file which triggers the fileSystemWatcher causes all the
other files to be processed as well.

Thanks
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
>I forgot to say that if I keep my object in an application variable,then
>the persistence problem will be solved,right?


Yes. However, be aware that an ASP.Net application will stop running when
it is idle (no requests) for a period of more than (by default) 20
minutes. When the application is stopped, the FileSystemWatcher will be
stopped. When the application restarts, the FileSystemWatcher will be
restarted as well. HOWEVER, any changes to the file system that the
Watcher is supposed to watch during the idle interval will go unnoticed.
Now, as long as changes to the files in the folder are also done by the
ASP.Net app, there will BE no changes while the app is stopped. So, while
I can't answer your question directly, this information, plus what you
already know, should give you the solution you need.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:eJ***************@TK2MSFTNGP12.phx.gbl...
I forgot to say that if I keep my object in an application variable,then
the persistence problem will be solved,right?

Thanks
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u8****************@tk2msftngp13.phx.gbl...
Your FileSystemWatcher is scoped to the method in which you instantiate
it. That means that it goes out of scope and is not available as soon
as the method returns. It may hang around for a bit since you have no
code to dispose it at any point, but you need to bone up on scope and
state. Here's a primer:

Scope is the "area of influence" of a variable. In a class, you have
global and local variables. Global variables are declared outside of
any methods, and are therefore "visible" to all members of the class.
Local variables are declared inside a method, and are therefore
"visible" only to other variables within a single instance (call) of
the method. Once the method returns, it is removed from the stack, and
everything in it becomes available for garbage collection.

Note that this differs from public, private, etc. These are also
definitions of scope, but are more related to encapsulation. Public
members of a class are "visible" from other classes. Private members
are not. Etc.

State refers to the persistence of an object (class instance or
primitive) in memory. Whenever an object is instantiated (created), it
must reside in memory somewhere. The lifetime of an object is limited
to the lifetime of the container in which it resides. A method is
instantiated, just like a variable, whenever you call it. And just like
a variable, when it returns, it is available for garbage collection.
The only way to persist an instance is to put it into something else
that persists. Hence, ASP.Net, which operates using HTTP, which is
stateless, has mechanisms for maintaining state, such as Session,
Application, and ViewState.

The global.asax class, as I mentioned in my earlier reply, is a
persistent class, but it's methods are not. They are instantiated like
any other methods, and pass out of scope as soon as they return.

I hope you will study what I've said, and continue to study how OOP
works as you go. In the meantime, you need to understand how to persist
your FileSystemWatcher, as well as making sure that when you are
finished with it, you dispose it.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:e5**************@TK2MSFTNGP14.phx.gbl...
> Here is what I have done .I have created a class and I instanciate
> that class in Application_Start method of my Global.asax ere is the
> code:
>
> ********Gloabl.asax:
> //Sets up a wacher on an specific shared folder to pickup zip files
>
> IFPWatcherComponent ifpWacher=new
> IFPWatcherComponent(ConfigurationSettings.AppSetti ngs[
> "MonitorPath"]);
>
>
>
> ********MyClass:
>
> /// </summary>
> public class IFPWatcherComponent:BusinessObject
> {
> string PathToMonitor=null;
>
> public IFPWatcherComponent(string PathToMonitor)
> {
>
> try
> {
> this.PathToMonitor = PathToMonitor;
> //Check to see if Web.config has appropriate settings
> if (this.PathToMonitor.Trim().Length==0 ) return;
> // Make a reference to a directory.
> DirectoryInfo di = new DirectoryInfo(this.PathToMonitor);
> // Create the directory only if it does not already exist.
> if (di.Exists == false)
> di.Create();
> // create an instance of FileSystemWatcher object and assign path
> to monitor
> FileSystemWatcher watcher = new FileSystemWatcher();
> // set necessary filters
> watcher.Path = this.PathToMonitor;
> //Watch for changes in FileName
> watcher.NotifyFilter = NotifyFilters.FileName;
> // watch zip files
> watcher.Filter = "*.zip";
> //Add appropriate event handler
> watcher.Created += new FileSystemEventHandler(OnCreated);
> watcher.EnableRaisingEvents = true;
> }
> catch
> {
> throw;
> }
> }
> private void OnCreated(object source, FileSystemEventArgs e)
> {
> FileStream oImg=null;
> BinaryReader oBinaryReader=null;
>
> Uploader uploader=new Uploader();
> uploader.ComeFrom="88";
> uploader.Comments="comment";
> uploader.CreatedByUser="test";
> uploader.FileName=e.Name;
>
> try
> {
>
> oImg = new FileStream (e.FullPath,FileMode.Open,FileAccess.Read);
> oBinaryReader = new BinaryReader(oImg);
> byte[] oImgByteArray = oBinaryReader.ReadBytes((int) oImg.Length);
> uploader.FileBody=oImgByteArray;
>
> uploader.RecordType=Business.IFP.RecordType.IFP_UP LOAD;
> uploader.Upload();
> uploader=null;
>
> }
> catch(Exception ee)
> {
> *******************I don't know how to handle the exception
> here??***********************
> }
> finally
> {
> if (oBinaryReader!=null) oBinaryReader.Close();
> if (oImg!=null) oImg.Close();
>
> }
> }
>
> "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
> news:ud**************@TK2MSFTNGP09.phx.gbl...
>> Are you sure you are on the right track? A FileSystemWatcher object
>> has to
>> exist somewhere to be able to watch. An asp.net application doesn't
>> exist
>> anywhere but between a client http request and the server response. A
>> very
>> short time. Do you expect the watcher to catch something only when
>> the
>> server is busy serving client requests?
>>
>> Eliyahu
>>
>>
>> "J-T" <Ra****@microsft.com> wrote in message
>> news:%2****************@TK2MSFTNGP15.phx.gbl...
>>> We are working on an asp.net application which is a 3-tier
>>> application.I
>> was
>>> aksed to create a component which monitors a folder and gets the
>>> file and
>>> pass them to a class library in our business logic layer(so far so
>>> good
>> and
>>> easy).I initialize my class which is using a FileSystemWatcher in my
>>> Global.asax and everything works fine.I have found
>>> FileSystemWatcher
>> class
>>> not very reliable and sometimes it behavies unexpectedly.I'm afriad
>>> that
>> it
>>> brings down the whole application.Is there a better way of doing
>>> this
>>> **Inside Asp.Net application**.I can't use antother application like
>> windows
>>> service or schedault taks.Everything needs to be done is ASP.NET
>>> application.
>>>
>>>
>>> Thanks a lot
>>>
>>>
>>
>>
>
>



Nov 19 '05 #18

P: n/a
J-T
I don't need the data immidiately at all.I need to get them sometimes
anyway.
just a timer and System.IO to check and keep track of the contents of the
folder you mean I should implement a timer in my class which makes my object to be
executed at a time interval for changes in an specific folder?

Thanks
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... Or how about this:

OnCreate event of the file ,I query the directory for all the files of
the type of I want and loop through them and enforce what I want.In the
way even if the application is in idle mode and filesystemWatcher is down
as well,the next file which triggers the fileSystemWatcher causes all the
other files to be processed as well.


If you're going to do that, you don't need anything right away, right? In
that case, you don't need a FileSystemWatcher at all, just a timer and
System.IO to check and keep track of the contents of the folder. Problem
solved, at least if you don't need the data immediately.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"Ray5531" <Ra****@microsft.com> wrote in message
news:OV**************@TK2MSFTNGP14.phx.gbl...
Or how about this:

OnCreate event of the file ,I query the directory for all the files of
the type of I want and loop through them and enforce what I want.In the
way even if the application is in idle mode and filesystemWatcher is down
as well,the next file which triggers the fileSystemWatcher causes all the
other files to be processed as well.

Thanks
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
>I forgot to say that if I keep my object in an application
>variable,then the persistence problem will be solved,right?

Yes. However, be aware that an ASP.Net application will stop running
when it is idle (no requests) for a period of more than (by default) 20
minutes. When the application is stopped, the FileSystemWatcher will be
stopped. When the application restarts, the FileSystemWatcher will be
restarted as well. HOWEVER, any changes to the file system that the
Watcher is supposed to watch during the idle interval will go unnoticed.
Now, as long as changes to the files in the folder are also done by the
ASP.Net app, there will BE no changes while the app is stopped. So,
while I can't answer your question directly, this information, plus what
you already know, should give you the solution you need.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:eJ***************@TK2MSFTNGP12.phx.gbl...
I forgot to say that if I keep my object in an application variable,then
the persistence problem will be solved,right?

Thanks
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u8****************@tk2msftngp13.phx.gbl...
> Your FileSystemWatcher is scoped to the method in which you
> instantiate it. That means that it goes out of scope and is not
> available as soon as the method returns. It may hang around for a bit
> since you have no code to dispose it at any point, but you need to
> bone up on scope and state. Here's a primer:
>
> Scope is the "area of influence" of a variable. In a class, you have
> global and local variables. Global variables are declared outside of
> any methods, and are therefore "visible" to all members of the class.
> Local variables are declared inside a method, and are therefore
> "visible" only to other variables within a single instance (call) of
> the method. Once the method returns, it is removed from the stack, and
> everything in it becomes available for garbage collection.
>
> Note that this differs from public, private, etc. These are also
> definitions of scope, but are more related to encapsulation. Public
> members of a class are "visible" from other classes. Private members
> are not. Etc.
>
> State refers to the persistence of an object (class instance or
> primitive) in memory. Whenever an object is instantiated (created), it
> must reside in memory somewhere. The lifetime of an object is limited
> to the lifetime of the container in which it resides. A method is
> instantiated, just like a variable, whenever you call it. And just
> like a variable, when it returns, it is available for garbage
> collection. The only way to persist an instance is to put it into
> something else that persists. Hence, ASP.Net, which operates using
> HTTP, which is stateless, has mechanisms for maintaining state, such
> as Session, Application, and ViewState.
>
> The global.asax class, as I mentioned in my earlier reply, is a
> persistent class, but it's methods are not. They are instantiated like
> any other methods, and pass out of scope as soon as they return.
>
> I hope you will study what I've said, and continue to study how OOP
> works as you go. In the meantime, you need to understand how to
> persist your FileSystemWatcher, as well as making sure that when you
> are finished with it, you dispose it.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> Sometimes you eat the elephant.
> Sometimes the elephant eats you.
>
> "J-T" <Ra****@microsft.com> wrote in message
> news:e5**************@TK2MSFTNGP14.phx.gbl...
>> Here is what I have done .I have created a class and I instanciate
>> that class in Application_Start method of my Global.asax ere is the
>> code:
>>
>> ********Gloabl.asax:
>> //Sets up a wacher on an specific shared folder to pickup zip files
>>
>> IFPWatcherComponent ifpWacher=new
>> IFPWatcherComponent(ConfigurationSettings.AppSetti ngs[
>> "MonitorPath"]);
>>
>>
>>
>> ********MyClass:
>>
>> /// </summary>
>> public class IFPWatcherComponent:BusinessObject
>> {
>> string PathToMonitor=null;
>>
>> public IFPWatcherComponent(string PathToMonitor)
>> {
>>
>> try
>> {
>> this.PathToMonitor = PathToMonitor;
>> //Check to see if Web.config has appropriate settings
>> if (this.PathToMonitor.Trim().Length==0 ) return;
>> // Make a reference to a directory.
>> DirectoryInfo di = new DirectoryInfo(this.PathToMonitor);
>> // Create the directory only if it does not already exist.
>> if (di.Exists == false)
>> di.Create();
>> // create an instance of FileSystemWatcher object and assign path
>> to monitor
>> FileSystemWatcher watcher = new FileSystemWatcher();
>> // set necessary filters
>> watcher.Path = this.PathToMonitor;
>> //Watch for changes in FileName
>> watcher.NotifyFilter = NotifyFilters.FileName;
>> // watch zip files
>> watcher.Filter = "*.zip";
>> //Add appropriate event handler
>> watcher.Created += new FileSystemEventHandler(OnCreated);
>> watcher.EnableRaisingEvents = true;
>> }
>> catch
>> {
>> throw;
>> }
>> }
>> private void OnCreated(object source, FileSystemEventArgs e)
>> {
>> FileStream oImg=null;
>> BinaryReader oBinaryReader=null;
>>
>> Uploader uploader=new Uploader();
>> uploader.ComeFrom="88";
>> uploader.Comments="comment";
>> uploader.CreatedByUser="test";
>> uploader.FileName=e.Name;
>>
>> try
>> {
>>
>> oImg = new FileStream (e.FullPath,FileMode.Open,FileAccess.Read);
>> oBinaryReader = new BinaryReader(oImg);
>> byte[] oImgByteArray = oBinaryReader.ReadBytes((int) oImg.Length);
>> uploader.FileBody=oImgByteArray;
>>
>> uploader.RecordType=Business.IFP.RecordType.IFP_UP LOAD;
>> uploader.Upload();
>> uploader=null;
>>
>> }
>> catch(Exception ee)
>> {
>> *******************I don't know how to handle the exception
>> here??***********************
>> }
>> finally
>> {
>> if (oBinaryReader!=null) oBinaryReader.Close();
>> if (oImg!=null) oImg.Close();
>>
>> }
>> }
>>
>> "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
>> news:ud**************@TK2MSFTNGP09.phx.gbl...
>>> Are you sure you are on the right track? A FileSystemWatcher object
>>> has to
>>> exist somewhere to be able to watch. An asp.net application doesn't
>>> exist
>>> anywhere but between a client http request and the server response.
>>> A very
>>> short time. Do you expect the watcher to catch something only when
>>> the
>>> server is busy serving client requests?
>>>
>>> Eliyahu
>>>
>>>
>>> "J-T" <Ra****@microsft.com> wrote in message
>>> news:%2****************@TK2MSFTNGP15.phx.gbl...
>>>> We are working on an asp.net application which is a 3-tier
>>>> application.I
>>> was
>>>> aksed to create a component which monitors a folder and gets the
>>>> file and
>>>> pass them to a class library in our business logic layer(so far so
>>>> good
>>> and
>>>> easy).I initialize my class which is using a FileSystemWatcher in
>>>> my
>>>> Global.asax and everything works fine.I have found
>>>> FileSystemWatcher
>>> class
>>>> not very reliable and sometimes it behavies unexpectedly.I'm afriad
>>>> that
>>> it
>>>> brings down the whole application.Is there a better way of doing
>>>> this
>>>> **Inside Asp.Net application**.I can't use antother application
>>>> like
>>> windows
>>>> service or schedault taks.Everything needs to be done is ASP.NET
>>>> application.
>>>>
>>>>
>>>> Thanks a lot
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Nov 19 '05 #19

P: n/a
I mean that you should create a timer in your Application_OnStart event
handler, store it in the Application Cache, and let its Elapsed event
handler do the work. If your Application stops, the timer stops. But when
the Application starts, the timer restarts.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <J-*@microsft.com> wrote in message
news:un*************@TK2MSFTNGP12.phx.gbl...
I don't need the data immidiately at all.I need to get them sometimes
anyway.
just a timer and System.IO to check and keep track of the contents of
the folder you mean I should implement a timer in my class which makes my object to
be executed at a time interval for changes in an specific folder?

Thanks
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... Or how about this:

OnCreate event of the file ,I query the directory for all the files of
the type of I want and loop through them and enforce what I want.In the
way even if the application is in idle mode and filesystemWatcher is
down as well,the next file which triggers the fileSystemWatcher causes
all the other files to be processed as well.


If you're going to do that, you don't need anything right away, right? In
that case, you don't need a FileSystemWatcher at all, just a timer and
System.IO to check and keep track of the contents of the folder. Problem
solved, at least if you don't need the data immediately.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"Ray5531" <Ra****@microsft.com> wrote in message
news:OV**************@TK2MSFTNGP14.phx.gbl...
Or how about this:

OnCreate event of the file ,I query the directory for all the files of
the type of I want and loop through them and enforce what I want.In the
way even if the application is in idle mode and filesystemWatcher is
down as well,the next file which triggers the fileSystemWatcher causes
all the other files to be processed as well.

Thanks
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
>I forgot to say that if I keep my object in an application
>variable,then the persistence problem will be solved,right?

Yes. However, be aware that an ASP.Net application will stop running
when it is idle (no requests) for a period of more than (by default) 20
minutes. When the application is stopped, the FileSystemWatcher will be
stopped. When the application restarts, the FileSystemWatcher will be
restarted as well. HOWEVER, any changes to the file system that the
Watcher is supposed to watch during the idle interval will go
unnoticed. Now, as long as changes to the files in the folder are also
done by the ASP.Net app, there will BE no changes while the app is
stopped. So, while I can't answer your question directly, this
information, plus what you already know, should give you the solution
you need.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

"J-T" <Ra****@microsft.com> wrote in message
news:eJ***************@TK2MSFTNGP12.phx.gbl...
>I forgot to say that if I keep my object in an application
>variable,then the persistence problem will be solved,right?
>
> Thanks
> "Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
> news:u8****************@tk2msftngp13.phx.gbl...
>> Your FileSystemWatcher is scoped to the method in which you
>> instantiate it. That means that it goes out of scope and is not
>> available as soon as the method returns. It may hang around for a bit
>> since you have no code to dispose it at any point, but you need to
>> bone up on scope and state. Here's a primer:
>>
>> Scope is the "area of influence" of a variable. In a class, you have
>> global and local variables. Global variables are declared outside of
>> any methods, and are therefore "visible" to all members of the class.
>> Local variables are declared inside a method, and are therefore
>> "visible" only to other variables within a single instance (call) of
>> the method. Once the method returns, it is removed from the stack,
>> and everything in it becomes available for garbage collection.
>>
>> Note that this differs from public, private, etc. These are also
>> definitions of scope, but are more related to encapsulation. Public
>> members of a class are "visible" from other classes. Private members
>> are not. Etc.
>>
>> State refers to the persistence of an object (class instance or
>> primitive) in memory. Whenever an object is instantiated (created),
>> it must reside in memory somewhere. The lifetime of an object is
>> limited to the lifetime of the container in which it resides. A
>> method is instantiated, just like a variable, whenever you call it.
>> And just like a variable, when it returns, it is available for
>> garbage collection. The only way to persist an instance is to put it
>> into something else that persists. Hence, ASP.Net, which operates
>> using HTTP, which is stateless, has mechanisms for maintaining state,
>> such as Session, Application, and ViewState.
>>
>> The global.asax class, as I mentioned in my earlier reply, is a
>> persistent class, but it's methods are not. They are instantiated
>> like any other methods, and pass out of scope as soon as they return.
>>
>> I hope you will study what I've said, and continue to study how OOP
>> works as you go. In the meantime, you need to understand how to
>> persist your FileSystemWatcher, as well as making sure that when you
>> are finished with it, you dispose it.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> .Net Developer
>> Sometimes you eat the elephant.
>> Sometimes the elephant eats you.
>>
>> "J-T" <Ra****@microsft.com> wrote in message
>> news:e5**************@TK2MSFTNGP14.phx.gbl...
>>> Here is what I have done .I have created a class and I instanciate
>>> that class in Application_Start method of my Global.asax ere is the
>>> code:
>>>
>>> ********Gloabl.asax:
>>> //Sets up a wacher on an specific shared folder to pickup zip files
>>>
>>> IFPWatcherComponent ifpWacher=new
>>> IFPWatcherComponent(ConfigurationSettings.AppSetti ngs[
>>> "MonitorPath"]);
>>>
>>>
>>>
>>> ********MyClass:
>>>
>>> /// </summary>
>>> public class IFPWatcherComponent:BusinessObject
>>> {
>>> string PathToMonitor=null;
>>>
>>> public IFPWatcherComponent(string PathToMonitor)
>>> {
>>>
>>> try
>>> {
>>> this.PathToMonitor = PathToMonitor;
>>> //Check to see if Web.config has appropriate settings
>>> if (this.PathToMonitor.Trim().Length==0 ) return;
>>> // Make a reference to a directory.
>>> DirectoryInfo di = new DirectoryInfo(this.PathToMonitor);
>>> // Create the directory only if it does not already exist.
>>> if (di.Exists == false)
>>> di.Create();
>>> // create an instance of FileSystemWatcher object and assign path
>>> to monitor
>>> FileSystemWatcher watcher = new FileSystemWatcher();
>>> // set necessary filters
>>> watcher.Path = this.PathToMonitor;
>>> //Watch for changes in FileName
>>> watcher.NotifyFilter = NotifyFilters.FileName;
>>> // watch zip files
>>> watcher.Filter = "*.zip";
>>> //Add appropriate event handler
>>> watcher.Created += new FileSystemEventHandler(OnCreated);
>>> watcher.EnableRaisingEvents = true;
>>> }
>>> catch
>>> {
>>> throw;
>>> }
>>> }
>>> private void OnCreated(object source, FileSystemEventArgs e)
>>> {
>>> FileStream oImg=null;
>>> BinaryReader oBinaryReader=null;
>>>
>>> Uploader uploader=new Uploader();
>>> uploader.ComeFrom="88";
>>> uploader.Comments="comment";
>>> uploader.CreatedByUser="test";
>>> uploader.FileName=e.Name;
>>>
>>> try
>>> {
>>>
>>> oImg = new FileStream (e.FullPath,FileMode.Open,FileAccess.Read);
>>> oBinaryReader = new BinaryReader(oImg);
>>> byte[] oImgByteArray = oBinaryReader.ReadBytes((int)
>>> oImg.Length);
>>> uploader.FileBody=oImgByteArray;
>>>
>>> uploader.RecordType=Business.IFP.RecordType.IFP_UP LOAD;
>>> uploader.Upload();
>>> uploader=null;
>>>
>>> }
>>> catch(Exception ee)
>>> {
>>> *******************I don't know how to handle the exception
>>> here??***********************
>>> }
>>> finally
>>> {
>>> if (oBinaryReader!=null) oBinaryReader.Close();
>>> if (oImg!=null) oImg.Close();
>>>
>>> }
>>> }
>>>
>>> "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
>>> news:ud**************@TK2MSFTNGP09.phx.gbl...
>>>> Are you sure you are on the right track? A FileSystemWatcher object
>>>> has to
>>>> exist somewhere to be able to watch. An asp.net application doesn't
>>>> exist
>>>> anywhere but between a client http request and the server response.
>>>> A very
>>>> short time. Do you expect the watcher to catch something only when
>>>> the
>>>> server is busy serving client requests?
>>>>
>>>> Eliyahu
>>>>
>>>>
>>>> "J-T" <Ra****@microsft.com> wrote in message
>>>> news:%2****************@TK2MSFTNGP15.phx.gbl...
>>>>> We are working on an asp.net application which is a 3-tier
>>>>> application.I
>>>> was
>>>>> aksed to create a component which monitors a folder and gets the
>>>>> file and
>>>>> pass them to a class library in our business logic layer(so far so
>>>>> good
>>>> and
>>>>> easy).I initialize my class which is using a FileSystemWatcher in
>>>>> my
>>>>> Global.asax and everything works fine.I have found
>>>>> FileSystemWatcher
>>>> class
>>>>> not very reliable and sometimes it behavies unexpectedly.I'm
>>>>> afriad that
>>>> it
>>>>> brings down the whole application.Is there a better way of doing
>>>>> this
>>>>> **Inside Asp.Net application**.I can't use antother application
>>>>> like
>>>> windows
>>>>> service or schedault taks.Everything needs to be done is ASP.NET
>>>>> application.
>>>>>
>>>>>
>>>>> Thanks a lot
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Nov 19 '05 #20

P: n/a
J-T
Thanks Kevin for all the helps and follow ups.I appreciate it.
I got it finally up and working.Here is the code

**********My Global.asax :

IFPWatcherComponent ifpWacher=new IFPWatcherComponent(
ConfigurationSettings.AppSettings["MonitorPath"],
int.Parse(ConfigurationSettings.AppSettings["SimultaniousNumberOfFiles"]));

Authorization.Current.Initialize();
try
{
Application.Lock();
Application.Add("IFPWatcherComponent",ifpWacher);
}
finally
{
Application.UnLock();

**********Class:

public class IFPWatcherComponent: Timer
{

private string mDir="";
private string mirrorDir="";
private int iCount=1;
// Monitor directory
public string monitorDirectory
{
get { return this.mDir; }
set { this.mDir= value; }
}

// interval
public double timerInterval
{
get { return this.Interval; }
set { this.Interval= value; }
}
public IFPWatcherComponent(string MonitorPath,int FileCounts)
{

this.monitorDirectory=MonitorPath;
this.fileCounts=FileCounts;

try
{
//Check to see if Web.config has appropriate settings
if (this.monitorDirectory.Trim().Length==0 ) return;

// Make a reference to a Montitor directory.
DirectoryInfo diMonitor = new DirectoryInfo(this.monitorDirectory);
// Create the directory only if it does not already exist.
if (diMonitor.Exists == false)
diMonitor.Create();

this.Elapsed+=new ElapsedEventHandler(OnTimedEvent);
this.Interval=this.timerInterval;
this.Enabled=true;
}
catch
{
throw;
}
}

private void OnTimedEvent(object source, ElapsedEventArgs e)
{
//do whatever you want here
}
}
Nov 19 '05 #21

This discussion thread is closed

Replies have been disabled for this discussion.