472,988 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Prevents Events From Interrupting Events

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 status of the download changes.

Some of the events are used to tell the next file to download while
others manager other resources. However, on occasion, one event will
fire while the other is in the middle of a lock. Since the event hits
a locked resource, it cannot move and I get a deadlock.

What I would really like to do is have the events queue up and run one
at a time. I am thinking my problem is my design decision in the
beginning to avoid an extra thread by using events to handle download
progress. However, I would like to know if queueing threads is even
possible.

Thanks,
Travis

Aug 20 '07 #1
4 2001
Think on event channeling structure (an event manager) which will manage the
events and have a sync object between the event raising.
You can manage list of event , manage the registration/ unregistration and
invocation of them.

--
Sincerely
Yaron Karni
http://dotnetbible.blogspot.com/
"je**********@gmail.com" wrote:
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 status of the download changes.

Some of the events are used to tell the next file to download while
others manager other resources. However, on occasion, one event will
fire while the other is in the middle of a lock. Since the event hits
a locked resource, it cannot move and I get a deadlock.

What I would really like to do is have the events queue up and run one
at a time. I am thinking my problem is my design decision in the
beginning to avoid an extra thread by using events to handle download
progress. However, I would like to know if queueing threads is even
possible.

Thanks,
Travis

Aug 20 '07 #2
je**********@gmail.com wrote:
Is there a way to prevent one event from firing while another event is
already being fired?
No, not really. If you have complete control over the event, you could
add logic to the point in the code where the event is raised. But since
that's pretty obvious and since you're still asking the question, I'm
assuming you don't have complete control over the events (presumably
they are implemented in other classes you use but did not write).
I have a tool that extracts media from web pages and it has multiple
events firing when the status of the download changes.

Some of the events are used to tell the next file to download while
others manager other resources. However, on occasion, one event will
fire while the other is in the middle of a lock. Since the event hits
a locked resource, it cannot move and I get a deadlock.
Who caused the deadlock? Is your code the one that is using the locked
resources? If so, then you also need to design your architecture so
that you don't have one thread trying to get a resource another already
has while that other thread is trying to get the resource the first
thread already has.

If the code that caused the deadlock is outside your control, the author
of that code needs to fix it.
What I would really like to do is have the events queue up and run one
at a time. I am thinking my problem is my design decision in the
beginning to avoid an extra thread by using events to handle download
progress. However, I would like to know if queueing threads is even
possible.
I don't understand your comment that using events in some way avoids an
extra thread. Events and threads are orthogonal ideas; one does not
exclude the other, though it's true that if you want to prevent your
event handlers from deadlocking each other, one fix is to _not_ have
multiple threads.

How is it you believe that using an event has avoided a thread?

There are ways to ensure that execution of specific code is done in a
synchronous manner. The delegate type does in fact make this
potentially easier, since you can either create your own queue of
delegates with an object array for the parameters and process it
yourself, or take advantage of the Control.BeginInvoke() method to queue
execution of delegates on a very specific thread (the thread that owns
the control). But these methods aren't specific to events; you would
have to incorporate them into your own event handlers explicitly.

A better approach would be to understand why you are deadlocking and to
fix the design error in your code that led to that in the first place.

Pete
Aug 20 '07 #3
On Aug 20, 11:31 am, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com>
wrote:
jehugalea...@gmail.com wrote:
Is there a way to prevent one event from firing while another event is
already being fired?

No, not really. If you have complete control over the event, you could
add logic to the point in the code where the event is raised. But since
that's pretty obvious and since you're still asking the question, I'm
assuming you don't have complete control over the events (presumably
they are implemented in other classes you use but did not write).
I have a tool that extracts media from web pages and it has multiple
events firing when the status of the download changes.
Some of the events are used to tell the next file to download while
others manager other resources. However, on occasion, one event will
fire while the other is in the middle of a lock. Since the event hits
a locked resource, it cannot move and I get a deadlock.

Who caused the deadlock? Is your code the one that is using the locked
resources? If so, then you also need to design your architecture so
that you don't have one thread trying to get a resource another already
has while that other thread is trying to get the resource the first
thread already has.

If the code that caused the deadlock is outside your control, the author
of that code needs to fix it.
What I would really like to do is have the events queue up and run one
at a time. I am thinking my problem is my design decision in the
beginning to avoid an extra thread by using events to handle download
progress. However, I would like to know if queueing threads is even
possible.

I don't understand your comment that using events in some way avoids an
extra thread. Events and threads are orthogonal ideas; one does not
exclude the other, though it's true that if you want to prevent your
event handlers from deadlocking each other, one fix is to _not_ have
multiple threads.

How is it you believe that using an event has avoided a thread?

There are ways to ensure that execution of specific code is done in a
synchronous manner. The delegate type does in fact make this
potentially easier, since you can either create your own queue of
delegates with an object array for the parameters and process it
yourself, or take advantage of the Control.BeginInvoke() method to queue
execution of delegates on a very specific thread (the thread that owns
the control). But these methods aren't specific to events; you would
have to incorporate them into your own event handlers explicitly.

A better approach would be to understand why you are deadlocking and to
fix the design error in your code that led to that in the first place.

Pete
I got away from another thread by having events manage the download
process. In other words, I have an event set the next file to
download.

I am starting to think, however, that I should create another thread
to handle the downloading. This will help reduce some of the
complexity of overlapping event handlers and booleans.

Thanks for your response. By the way . . . is it possible for the same
thread to deadlock itself with the help of events? or is the lock
keyword ignored when it is the same thread?

Aug 20 '07 #4
je**********@gmail.com wrote:
I got away from another thread by having events manage the download
process. In other words, I have an event set the next file to
download.
That doesn't answer the question. Just having an event or an event
handler does not in and of itself avoid the use of a thread. In fact,
in many scenarios events are implemented as a way for a thread to easily
execute code that needs to execute when certain things happen in that
thread.
I am starting to think, however, that I should create another thread
to handle the downloading. This will help reduce some of the
complexity of overlapping event handlers and booleans.
Adding another thread will also add to the complexity of your design.
Since your design already has a deadlock condition as it is, I would be
surprised if you can fix that basic design issue by adding a new thread
and you could easily just make it harder to fix.
Thanks for your response. By the way . . . is it possible for the same
thread to deadlock itself with the help of events? or is the lock
keyword ignored when it is the same thread?
Thread synchronization isn't ignored when it occurs multiple times in
the same thread. However, it is nested without any problem or potential
for a thread deadlocking itself. So within the same thread, you can use
the lock() statement or similar synchronization mechanism multiple times
without any trouble.

For the best answers, you should put together a concise-but-complete
example of code that reliably reproduces the problem you're having and
post that here. Without that, it's very difficult to comment
intelligently on the specifics of your design and how you would best
avoid the deadlock issue.

Pete
Aug 20 '07 #5

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

Similar topics

0
by: Rea Peleg | last post by:
link to configuration file prevents user control download to internet explorer Hi I have a simple web application which consists an opening html page with a (windows form user) control which...
15
by: Michael Hill | last post by:
I have this cf script below where the javascript in it works perfectly i.e. a new window opens when I press 'click me' when I call it up using the url in the browser. But when I "POST" to it...
5
by: Bill Henning | last post by:
Does anyone know a good method of preventing keyboard and mouse events from interrupting processing? My situation is: 1) I need to track and handle all key and mouse events 2) I need to perform...
2
by: Rob Richardson | last post by:
Greetings! I am struggling to understand data binding in VB.Net, and it's slow going. I have a list box bound to a dataset that is filled from a SQL Server table. In addition to the list...
6
by: Jm | last post by:
Hi All I have a simple vb.net app that once run for some reason does not allow me to log off or shutdown the pc ? When i try to do so it will close my app and then will only shutdown or logoff...
8
by: andreas | last post by:
When I do a long calculation is there a possibility to interrupt this calculation properly? For i as integer = 1 to 100000000 do something next and retrieve the i at the moment of the...
1
by: Zamdrist | last post by:
Trying to get my tray icon application to work as expected. Normally when you close an opened try icon application it minimizes to the tray. I have that part working by interrupting the close even...
3
by: gsherp | last post by:
I have onchange in my javascript and there is no bug in the code. However, whenever a user uses the autofill feature in the browser, none of my javascript events are ever fired. This causes none of...
1
by: swethak | last post by:
Hi, I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add the events to calendar. In that code displys the...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.