473,378 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Events raised from other threads

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?
Nov 16 '05 #1
2 1246
John,

What I would do is have a flag that is set when the event is fired.
Then, in each of your methods, check the flag to see if the event fired. If
it did, then do nothing.

However, there are times it seems in your processing that you might not
care if you are disconnected anymore (for example, after you have downloaded
all the files, what do you care if you are disconnected?). You might want
to consider those cases as well.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Paulsson" <et*****************@hotmail.com> wrote in message
news:uB**************@TK2MSFTNGP09.phx.gbl...
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?

Nov 16 '05 #2

Thank's for your reply Nicholas! I'm processing the files directly on
the ftp server and need to stay connected through out the process.

I'll use a flag as you suggested together with some exception handling
then to abort processing on disconnects. Thank you.
Nicholas Paldino [.NET/C# MVP] wrote:
John,

What I would do is have a flag that is set when the event is fired.
Then, in each of your methods, check the flag to see if the event fired. If
it did, then do nothing.

However, there are times it seems in your processing that you might not
care if you are disconnected anymore (for example, after you have downloaded
all the files, what do you care if you are disconnected?). You might want
to consider those cases as well.

Hope this helps.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: GM | last post by:
Hi, My application has a need to cache a number of shared reference lists containing basic business objects. In order to improve performance these lists are fetched and updated in the...
4
by: Bardo | last post by:
Hi, I have a situation where I am capturing both a WMI event utilising the "ManagementEventWatcher" in the "System.Management" namespace, and a corresponding event ("EntryWritten") raised from...
3
by: Jacob | last post by:
I'm working on a class that needs to be called from a windows form, do it's work, and then, show progress back to the main form. I'm well aware that worker threads need to call Invoke for updates...
4
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on...
5
by: Bob Day | last post by:
Using vs 2003, vb.net It is not clear from the documentation, but it appears that a raised event will traverse up the call stack upwards until it reaches its handler. Is this correct? See the...
4
by: Curious Coder | last post by:
I have been tasked with a project that I do not think can be accomplished. Our company has an application that runs as an unmanaged ActiveX control on user desktops. It is designed to work with...
3
by: daan | last post by:
Hello, I have a problem and I can't get the solution for it :( I have a com dll, which i imported as a reference. The com object is part of a class which is multithreaded and will create...
5
by: Daniel | last post by:
Hey guys When you hook an event (c# 2.0 syntax): myEvent += MyMethodToFire; You need to also unsubscribe it to avoid a resource leak so that the object it is in gets garbage collected like so...
11
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When...
4
by: jehugaleahsa | last post by:
Hello: Is there a way to prevent one event from firing while another event is already being fired? I have a tool that extracts media from web pages and it has multiple events firing when the...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.