Re: ASP.NET Application and FileSystemWatcher
- From: "J-T" <J-T@xxxxxxxxxxxx>
- Date: Thu, 19 May 2005 14:11:31 -0700
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" <kevin@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:%23xwYM8KXFHA.3044@xxxxxxxxxxxxxxxxxxxxxxx
>> 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" <RayAll@xxxxxxxxxxxx> wrote in message
> news:OVU0hnJXFHA.1240@xxxxxxxxxxxxxxxxxxxxxxx
>> 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" <kevin@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> news:u4hBV2FXFHA.2540@xxxxxxxxxxxxxxxxxxxxxxx
>>> >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" <RayAll@xxxxxxxxxxxx> wrote in message
>>> news:eJoaHa%23WFHA.612@xxxxxxxxxxxxxxxxxxxxxxx
>>>>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" <kevin@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>>>> news:u8%23Jhf5WFHA.3864@xxxxxxxxxxxxxxxxxxxxxxx
>>>>> 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" <RayAll@xxxxxxxxxxxx> wrote in message
>>>>> news:e5ZZRqyWFHA.2288@xxxxxxxxxxxxxxxxxxxxxxx
>>>>>> 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.AppSettings[
>>>>>> "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_UPLOAD;
>>>>>> 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" <removemeegoldin@xxxxxxxxxxxxxx> wrote in message
>>>>>> news:udEvR5xWFHA.3188@xxxxxxxxxxxxxxxxxxxxxxx
>>>>>>> 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" <RayAll@xxxxxxxxxxxx> wrote in message
>>>>>>> news:%23QPGMNxWFHA.3540@xxxxxxxxxxxxxxxxxxxxxxx
>>>>>>>> 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
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
.
- Follow-Ups:
- Re: ASP.NET Application and FileSystemWatcher
- From: Kevin Spencer
- Re: ASP.NET Application and FileSystemWatcher
- References:
- ASP.NET Application and FileSystemWatcher
- From: J-T
- Re: ASP.NET Application and FileSystemWatcher
- From: Eliyahu Goldin
- Re: ASP.NET Application and FileSystemWatcher
- From: J-T
- Re: ASP.NET Application and FileSystemWatcher
- From: Kevin Spencer
- Re: ASP.NET Application and FileSystemWatcher
- From: J-T
- Re: ASP.NET Application and FileSystemWatcher
- From: Kevin Spencer
- Re: ASP.NET Application and FileSystemWatcher
- From: Ray5531
- Re: ASP.NET Application and FileSystemWatcher
- From: Kevin Spencer
- ASP.NET Application and FileSystemWatcher
- Prev by Date: Need help with file deletion script
- Next by Date: Raising events in a control
- Previous by thread: Re: ASP.NET Application and FileSystemWatcher
- Next by thread: Re: ASP.NET Application and FileSystemWatcher
- Index(es):
Relevant Pages
|