473,761 Members | 9,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2053
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**********@g mail.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**********@gm ail.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.BeginIn voke() 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...@Nn OwSlPiAnMk.com>
wrote:
jehugalea...@gm ail.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.BeginIn voke() 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**********@gm ail.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
1657
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 on click event should download an assembley from the server site to client ie. Opening page displays correctly with control when it does not include the
15
1851
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 from another script the javascript window does not open when I click "click me". Is cf writing something kludgy to the browser when I post to it causing the javascript not to execute??
5
3768
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 processing on certain key/mouse events 3) If key/mouse events interrupt processing, the events should not be discarded since they need to be handled but AFTER the current processing is complete
2
1269
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 box, I have two buttons on the form. When I click one, a data adapter's Fill() method gets data into the table, and the column the list box is bound to obligingly appears in the list box. The other button merely displays a message box when it
6
11271
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 if i attempt to do so once again ? Does anybody have any does why this would be so ?
8
1229
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 interrupting Thanks for any response
1
1390
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 in the Closing event by using e.Cancel = True. Unfortunately this also seems to interfere with closing the application when you shut down windows...windows won't shutdown until I explicit close my tray icon application, using a context menu...
3
2307
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 my functions to be called. Is there a way to listen for autofill events? such as onautofill? thanks, David.
1
4907
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 events when click on that date that perticular event displyed in a text box.But my requirement is to when click on that date that related event displyed in same td row not the text box. and also i add the events to that calendar.plz advice how to...
0
9531
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9957
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8780
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.