J
John Paulsson
I'm interested knowing best design principles for this "issue". I've got
a Windows form application which processes and updates some FTP files in
a predefined way. On an unexpected disconnect, an event is raised from
the client thread. When this happens, I want the Transaction() to abort
its process and instead do some other stuff inside the main thread.
Please have a look at the following pseudo-code:
private FTPClient m_ftp = null;
private ftphandle m_h = null;
Form1::OnLoad()
{
m_ftp = new FTPClient();
ftp.OnDisconnect += new FTPEventHandler(OnDisconnect);
m_h = ftp.Connect("127.0.0.1", "/files");
Transaction();
}
Form1::Transaction()
{
// Main thread
PrepareFiles(h);
AdjustFiles(h);
ProcessFiles(h);
CompleteFiles(h);
}
App:OnDisconnect()
{
// Event raised from a new thread created by FTPClient object
frmStatus.ShowModal();
}
If OnDisconnect is called, and I show this frmStatus form, the code
inside the Transaction function will still continue to run in the
background and try to interact using Form1.
Should I set a boolean member variable inside the OnDisconnect handler
and check it after every row in the Transaction function AND inside the
function it calls, and let them determine wheter Transaction should
abort or not, run Transaction() in a third thread and just kill it on
Disconnect, what's your suggestion?
a Windows form application which processes and updates some FTP files in
a predefined way. On an unexpected disconnect, an event is raised from
the client thread. When this happens, I want the Transaction() to abort
its process and instead do some other stuff inside the main thread.
Please have a look at the following pseudo-code:
private FTPClient m_ftp = null;
private ftphandle m_h = null;
Form1::OnLoad()
{
m_ftp = new FTPClient();
ftp.OnDisconnect += new FTPEventHandler(OnDisconnect);
m_h = ftp.Connect("127.0.0.1", "/files");
Transaction();
}
Form1::Transaction()
{
// Main thread
PrepareFiles(h);
AdjustFiles(h);
ProcessFiles(h);
CompleteFiles(h);
}
App:OnDisconnect()
{
// Event raised from a new thread created by FTPClient object
frmStatus.ShowModal();
}
If OnDisconnect is called, and I show this frmStatus form, the code
inside the Transaction function will still continue to run in the
background and try to interact using Form1.
Should I set a boolean member variable inside the OnDisconnect handler
and check it after every row in the Transaction function AND inside the
function it calls, and let them determine wheter Transaction should
abort or not, run Transaction() in a third thread and just kill it on
Disconnect, what's your suggestion?