Greetings,
I believe I have narrowed down my issues to one simple question, and I'm hoping someone with async events experience can help me out.
My question is: how is using EventsHelper.Fi reAsync() different from using EventsHelper.Fire() BUT having the listener's event handler spawn a new thread to do the work?
In my program, I have a data feed coming in and I have a separate form that has a DataGridView on it. Each time a message comes in (they come in very rapidly) I fire an event and the handler (which exists on the DataGridView's form) adds a row to the DataGridView.
Approach #1: use EventsHelper.Fi reAsync() to fire the events as they come in. This is nice because the slowness of adding rows to the DataGridView control doesn't slow down the incoming data feed AT ALL -- meaning, if there were other listeners to this event, their performance wouldn't suffer from the slow DataGridView. HOWEVER, this approach doesn't work because of the asynchronous nature, the rows aren't necessarily added in order (message 3 might be processed/added to the DataGridView before messages 1 and 2).
Approach #2: use EventsHelper.Fi re() (the synchronous version), and in the event handler, spawn a BackgroundWorke r that adds the message to the DataGridView. I don't like this approach because then EVERY handler of this event is going to have to do all this extra work, but I figured it was the only way I could ensure the messages (events) would be received in order. However what I noticed is this approach (spawning the BackgroundWorke r thread) doesn't really give a speed improvement over simply doing ALL the work in the same event thread.
Why isn't approach #2, with a BackgroundWorke r in the ONLY event handler as fast as approach #1?
I love the speed EventsHelper.Fi reAsync provides, but I need to maintain order of the events. If anyone has any advice, I'm all ears.
Thanks in advance!
RL
1 2524
To add to my confusion, I add a Thread.Sleep() call in my BackgroundWorke r's DoWork() function, and this allows the main (event-generating) thread to get through all of the messages quickly! Why should it matter if there's a Sleep call in the background worker's thread -- if it's on a separate thread, shouldn't the main (event-generating) thread be allowed to continue? -
void bw_DoWork(object sender, DoWorkEventArgs e)
-
{
-
OrderUpdateEventArgs updateEvent = (OrderUpdateEventArgs)e.Argument;
-
if (updateEvent.GetEventType() == OrderUpdateEventArgs.OrderUpdateEventType.EVENT_TYPE_FILL) {
-
Thread.Sleep(200); // this speeds up the calling thread! why!?
-
PerformTimeIntensiveTask();
-
}
-
}
-
void controller_OrderUpdated(object sender, OrderUpdateEventArgs updateEvent)
-
{
-
BackgroundWorker bw = new BackgroundWorker();
-
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
-
bw.RunWorkerAsync(updateEvent);
-
}
-
The Sleep call above allows the calling thread to process all of the messages as if there were ZERO delay from this event handler.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: MR |
last post by:
this is a question on how to design an TCP Listener application.
background:
There will be several threads that listen on several ports (one per port).
when another app requests to connect, the connection will be accepted. then
messages will be received and passed to the main thread via a delegate or
event for processing. Messages will also be sent in return to the other
application in an asynchronous manner.
Questions:
1) from what it...
|
by: Natalia DeBow |
last post by:
Hi,
I am working on a Windows-based client-server application. I am involved in
the development of the remote client modules. I am using asynchronous
delegates to obtain information from remote server and display this info on
the UI.
From doing some research, I know that the way my implementation works today
is not thread-safe, because essentially my worker thread updates the UI,
which is BAD. So, here I am trying to figure out how...
|
by: ALI-R |
last post by:
Hi All,
When we say events are processed asynchronously in for instance Sharepoint
,what dose it mean?
Thanks for your help.
Ali
|
by: Jason Dravet |
last post by:
Some time ago I wrote an application that controls the projectors in our
classrooms(turn on, turn off, and volume control). This application is
written in VB.net 2003. It was working perfectly until XP SP2 was installed
on the PCs. Now when the power on or power off button is pressed the
following message is displayed:
An unhandled exception has occurred in your application. If you click
Continue, the application will ignore this...
|
by: Gerda |
last post by:
Hi!
I've implemented many times an asynchronous call of a method with a call
backfunction successfully.
But to implement this with VB.NET is not so successfully. I can implement
all events ProcessingEvent, CompletedEvent, etc.
It works fine and copies all files in the background ...
Bit to make it perfekt I want to implement a callback function wich will be
| |
by: TrtnJohn |
last post by:
I have a multi-threaded class that I am creating that needs needs to raise
events when certain asynchronous events occur. I would always like the
events to be raised to the primary UI thread of any application that is using
my component. I can't just call raiseevent from the thread that catches the
asynchronous data. (In this case from a serial port). This is because I
have a separate thread reading from the serial device. How can I...
|
by: Ryan Liu |
last post by:
Hi,
I read Microsoft SDK,
ms-help://MS.NETFrameworkSDKv1.1/cpguidenf/html/cpovrasynchronousprogramming
overview.htm
there are 4 ways to call EndInvoke:
The code in this topic demonstrates four common ways to use BeginInvoke and
EndInvoke to make asynchronous calls. After calling BeginInvoke you can:
|
by: jan.loucka |
last post by:
I'm developing WinForms application in .NET 2.0 that talks to web
service. The automatically generated proxy (reference class) has got
methods for both synchronous and asynchronous invocations of the web
service methods. What I like about the asynchronous calls that they
use events. So when I call the web service operation is finished is
fires the event. So all my objects that I'm using in my client
application just subscribe to whatever...
|
by: jan.loucka |
last post by:
I'm developing WinForms application in .NET 2.0 that talks to web
service. The automatically generated proxy (reference class) has got
methods for both synchronous and asynchronous invocations of the web
service methods. What I like about the asynchronous calls that they
use events. So when I call the web service operation is finished is
fires the event. So all my objects that I'm using in my client
application just subscribe to whatever...
|
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,...
|
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...
| |
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |