P
P.J.M. Beker
Hi there,
I'm currently writing a program in which I use the FileMonitor to monitor a
folder in which I store downloaded images. I know that I can't add much
coding in the filemonitor's event in risk of losing some new entries, so
I've deceided to create an update thread. This thread is created when the
program's start and should (for various reason) run not in sync with the
Filemonitor.
The Filemonitor event creates an entry in a database table (lets call it
TEMP) in which it stores the location and name of a new image. The update
thread scans this table and if it finds any entries, is does a serie of
operations (hash calculation, check for multiple entries etc). The thread
then creates a new entry in table [QUEUE] in which it stores the image
title, location, hashvalue etc.Then it gets the next entry in table TEMP. If
there aren't any records left, it goes to sleep. When waking up it scans
table TEMP again.
Here is my problem. When terminating my program, the update thread should
stop, but only after it finishes processing the current image it's working
on. It should not create any corrupted/broken records. How can I prevent
this from happening?
// Main Program
private void FileMonitor_Created(Object sender, FileSystemEventArgs e)
{
// Creates a new record in table TEMP
CreateNewTempEntry(e.FullPath);
}
// Update Thread
private void ScanTempTable()
{
OleDbCommand myCmd = new OleDBCommand("SELECT * FROM TEMP");
myCmd.Connection = ...;
OleDbDataReader myReader = myCmd.ExecuteReader();
string myFile = "", myHash = "";
bool bFound = false;
while(myReader.Read())
{
myFile = myReader.GetString(0);
myHash = CalcHash(myFile);
bFound = Scan4MultipleImages(myHash)
-----------------------------------------------------------
// Thread isn't allow to stop here
WriteNewImageRecord(myFile, myHash, bFound);
// Thread can stop now
------------------------------------------------------------
}
// Sleep for a while
}
thnx in advance
Peter
I'm currently writing a program in which I use the FileMonitor to monitor a
folder in which I store downloaded images. I know that I can't add much
coding in the filemonitor's event in risk of losing some new entries, so
I've deceided to create an update thread. This thread is created when the
program's start and should (for various reason) run not in sync with the
Filemonitor.
The Filemonitor event creates an entry in a database table (lets call it
TEMP) in which it stores the location and name of a new image. The update
thread scans this table and if it finds any entries, is does a serie of
operations (hash calculation, check for multiple entries etc). The thread
then creates a new entry in table [QUEUE] in which it stores the image
title, location, hashvalue etc.Then it gets the next entry in table TEMP. If
there aren't any records left, it goes to sleep. When waking up it scans
table TEMP again.
Here is my problem. When terminating my program, the update thread should
stop, but only after it finishes processing the current image it's working
on. It should not create any corrupted/broken records. How can I prevent
this from happening?
// Main Program
private void FileMonitor_Created(Object sender, FileSystemEventArgs e)
{
// Creates a new record in table TEMP
CreateNewTempEntry(e.FullPath);
}
// Update Thread
private void ScanTempTable()
{
OleDbCommand myCmd = new OleDBCommand("SELECT * FROM TEMP");
myCmd.Connection = ...;
OleDbDataReader myReader = myCmd.ExecuteReader();
string myFile = "", myHash = "";
bool bFound = false;
while(myReader.Read())
{
myFile = myReader.GetString(0);
myHash = CalcHash(myFile);
bFound = Scan4MultipleImages(myHash)
-----------------------------------------------------------
// Thread isn't allow to stop here
WriteNewImageRecord(myFile, myHash, bFound);
// Thread can stop now
------------------------------------------------------------
}
// Sleep for a while
}
thnx in advance
Peter