Prompt how to implement the following features:
My application is a lot Thread server and receives the job to copy files from one directory to another. After receives a job is entered into the database and get in the queue.With the help of a timer, I queried the database every 10 seconds, and derive from the base of your new job. Each new task of copying a file is executed in a separate thread.Now you need to be able to suspend the execution in advance of copying the file / interrupt the flow.
Prompt how to make sure that I at any time to stop the flow.
application of this:
void Server::TimerShot()
{
CWorkThread *WThread = new CWorkThread(this);
connect(WThread, SIGNAL(finished()), WThread, SLOT(deleteLater()));
WThread
->start
(QThread::HighPriority);
}
void Server::TimerShot()
{
CWorkThread *WThread = new CWorkThread(this);
connect(WThread, SIGNAL(finished()), WThread, SLOT(deleteLater()));
WThread->start(QThread::HighPriority);
}
To copy to clipboard, switch view to plain text mode
void CWorkThread::run()
{
CWorkFiles files;
sInfo = db.GetNewTask();
db.CloseDB();
//File Operation blocked. While the file is not copied more than walk.
if(files.
CopyFileExPrg(QDir::toNativeSeparators(sInfo.
cFileName),
QDir::toNativeSeparators(sGInfo.
cDstPath),
true,
false, sInfo.
nSysId)) {
//OK
db.ChangeState(3, sInfo.cObjName, sInfo.cFileName, sInfo.nSysId);
db.CloseDB();
break;
}
else
{
//ERROR
db.ChangeState(33, sInfo.cObjName, sInfo.cFileName, sInfo.nSysId);
db.CloseDB();
break;
}
}
void CWorkThread::run()
{
CWorkFiles files;
sInfo = db.GetNewTask();
db.CloseDB();
//File Operation blocked. While the file is not copied more than walk.
if(files.CopyFileExPrg(QDir::toNativeSeparators(sInfo.cFileName),
QDir::toNativeSeparators(sGInfo.cDstPath), true, false, sInfo.nSysId))
{
//OK
db.ChangeState(3, sInfo.cObjName, sInfo.cFileName, sInfo.nSysId);
db.CloseDB();
break;
}
else
{
//ERROR
db.ChangeState(33, sInfo.cObjName, sInfo.cFileName, sInfo.nSysId);
db.CloseDB();
break;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks