Click here to Skip to main content
15,918,742 members
Home / Discussions / C#
   

C#

 
GeneralRe: Find a word using regular expression in c# Pin
PeriyasamyRamachandran2-Mar-10 20:28
PeriyasamyRamachandran2-Mar-10 20:28 
Questiondatagridviewrow conversion Pin
Member 5903102-Mar-10 19:28
Member 5903102-Mar-10 19:28 
Questionhow to write to a specific range in excel ? [modified] Pin
tonyonlinux2-Mar-10 19:15
tonyonlinux2-Mar-10 19:15 
AnswerRe: how to write to a specific range in excel ? Pin
tonyonlinux3-Mar-10 8:22
tonyonlinux3-Mar-10 8:22 
QuestionC# win application with web-browser control HANGS after some time Pin
BalajiRamasamy2-Mar-10 18:55
BalajiRamasamy2-Mar-10 18:55 
AnswerRe: C# win application with web-browser control HANGS after some time Pin
Saksida Bojan2-Mar-10 19:06
Saksida Bojan2-Mar-10 19:06 
GeneralRe: C# win application with web-browser control HANGS after some time Pin
BalajiRamasamy2-Mar-10 19:19
BalajiRamasamy2-Mar-10 19:19 
AnswerRe: C# win application with web-browser control HANGS after some time Pin
Luc Pattyn3-Mar-10 1:57
sitebuilderLuc Pattyn3-Mar-10 1:57 
Questiondatagridview insertion Pin
Member 5903102-Mar-10 18:21
Member 5903102-Mar-10 18:21 
AnswerMessage Closed Pin
2-Mar-10 18:35
stancrm2-Mar-10 18:35 
GeneralRe: datagridview insertion Pin
Member 5903102-Mar-10 18:37
Member 5903102-Mar-10 18:37 
AnswerRe: datagridview insertion Pin
Arindam Tewary2-Mar-10 20:16
professionalArindam Tewary2-Mar-10 20:16 
QuestionHow to Create Virtual Drive? Pin
Pawan Kiran2-Mar-10 18:17
Pawan Kiran2-Mar-10 18:17 
AnswerRe: How to Create Virtual Drive? Pin
Saksida Bojan2-Mar-10 18:42
Saksida Bojan2-Mar-10 18:42 
GeneralRe: How to Create Virtual Drive? Pin
Pawan Kiran2-Mar-10 18:57
Pawan Kiran2-Mar-10 18:57 
GeneralRe: How to Create Virtual Drive? Pin
Saksida Bojan2-Mar-10 19:00
Saksida Bojan2-Mar-10 19:00 
QuestionMessage Removed Pin
2-Mar-10 9:09
Kennebel2-Mar-10 9:09 
AnswerRe: WPF Nested Grid Sizing Pin
AspDotNetDev2-Mar-10 17:12
protectorAspDotNetDev2-Mar-10 17:12 
GeneralRe: WPF Nested Grid Sizing Pin
Kennebel3-Mar-10 3:13
Kennebel3-Mar-10 3:13 
QuestionNot sure why second Access Rule is required for User account write access Pin
CTaylor892-Mar-10 8:31
CTaylor892-Mar-10 8:31 
AnswerRe: Not sure why second Access Rule is required for User account write access Pin
DaveyM692-Mar-10 10:22
professionalDaveyM692-Mar-10 10:22 
GeneralRe: Not sure why second Access Rule is required for User account write access Pin
CTaylor892-Mar-10 12:12
CTaylor892-Mar-10 12:12 
AnswerRe: Not sure why second Access Rule is required for User account write access Pin
CTaylor892-Mar-10 13:34
CTaylor892-Mar-10 13:34 
GeneralRe: Not sure why second Access Rule is required for User account write access Pin
DaveyM692-Mar-10 13:56
professionalDaveyM692-Mar-10 13:56 
QuestionWindows Service, FileSystemWatcher + Polling [modified] Pin
krazykoder2-Mar-10 6:23
krazykoder2-Mar-10 6:23 
Hello,

I am developing a windows service that will process
xml files as they come in.
I have a FileSystemWatcher that is watching a folder
and processing the files when the fileSystemWatcher1_Created
event is raised.
I created a FileProcessor class that handles processing a file,
it splits the incoming xml file into many different files and
then pushes data to a database using sqlBulkCopy, etc.

So right now my code looks like this...
private void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
{
    Logger.AddInformation(string.Format("File {0} {1}.", e.Name, e.ChangeType));

    FileProcessor fileProcessor = new FileProcessor(e.Name);
    bool retValue = fileProcessor .ProcessFile();

    Logger.AddInformation(string.Format("Processed File {0} {1}.", e.Name, retValue ? "Successfully" : "Unsuccessfully"));
}


But I have read that the FileSystemWatcher can be unreliable in some
situations so I wanted to build in a backup mechanism that polls
and checks the folder periodically for files that may have been missed,
or were already in the folder when the service was started, etc.

So my goal was to have some kind of object that maintains a queue
of files that need to be processed.
Then when the fileSystemWatcher1_Created event is raised instead of
processing the file at that time I would just add the file to the queue.
And also when the polling if I encountered a new file I would add it to the
queue as well (making sure that file was not already processed or already
on the queue).

Problem is I'm not really sure how to implement this.
I'm imagining I may need another Thread or Threads.
I have some code that creates another thread and uses a timer so that
could potentially be my backup polling mechanism running every x seconds
scanning folder and adding files to the queue.

But I still don't fully understand how to make it work.
I'm feeling like something would need to manage the queue and keep
processing the files until it's empty, and not sure if that should be
happening on the main windows service thread or a separate thread, etc.

I'm trying to keep the design as simple as possible and hopefully limit it
to just 1 windows service.
I just want to process the files 1 by 1 anyway, so I'm not looking to spawn
a new thread for every file or anything like that.

Can anyone point me in the right direction?
Maybe slap together some skeleton code that would help me understand.
Or are there any good articles or examples of doing something like this or
a design pattern I should look into?

Thanks!
modified on Tuesday, March 2, 2010 1:29 PM

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.