I have a windows form of which I will be saving the user's selections from
DropDownBoxes, CheckBoxes, and RadioButtons. Once the choices are collected,
I really will have no use for any of the controls. Is there a benefit of
using Control.BeginIn voke opposed to ThreadPool.Queu eWorkItem? From the
threads I have briefly scanned over on the www, there really is no difference
other. Some have mentioned that ThreadPool.Queu eWorkItem maybe faster, but
thats about all. Any thoughts? 3 6053
RWF,
The question one has to ask is, to what end are you doing this?
These things are actually very different.
Control.BeginIn voke/Invoke will cause the delegate passed to it to be
executed on the thread that calls need to be synchronized on. Windows
controls require changes to them to be executed on the thread that created
them. When you call BeginInvoke/Invoke, it makes sure that the call is
marshaled correctly.
When you call QueueWorkItem, a method is executed on another thread of
execution.
Now, when you call BeginInvoke, it will call Invoke on another thread of
execution, through QueueWorkItem, but the call ultimately will end up being
called on the thread that created the control. It's just that you don't
have to wait for Invoke to return on the thread you call BeginInvoke on.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"RWF" <RW*@discussion s.microsoft.com > wrote in message
news:3D******** *************** ***********@mic rosoft.com... I have a windows form of which I will be saving the user's selections from DropDownBoxes, CheckBoxes, and RadioButtons. Once the choices are collected, I really will have no use for any of the controls. Is there a benefit of using Control.BeginIn voke opposed to ThreadPool.Queu eWorkItem? From the threads I have briefly scanned over on the www, there really is no difference other. Some have mentioned that ThreadPool.Queu eWorkItem maybe faster, but thats about all. Any thoughts?
Thanks Nicholas, that helps a bunch.
"Nicholas Paldino [.NET/C# MVP]" wrote: RWF,
The question one has to ask is, to what end are you doing this?
These things are actually very different.
Control.BeginIn voke/Invoke will cause the delegate passed to it to be executed on the thread that calls need to be synchronized on. Windows controls require changes to them to be executed on the thread that created them. When you call BeginInvoke/Invoke, it makes sure that the call is marshaled correctly.
When you call QueueWorkItem, a method is executed on another thread of execution.
Now, when you call BeginInvoke, it will call Invoke on another thread of execution, through QueueWorkItem, but the call ultimately will end up being called on the thread that created the control. It's just that you don't have to wait for Invoke to return on the thread you call BeginInvoke on.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"RWF" <RW*@discussion s.microsoft.com > wrote in message news:3D******** *************** ***********@mic rosoft.com...I have a windows form of which I will be saving the user's selections from DropDownBoxes, CheckBoxes, and RadioButtons. Once the choices are collected, I really will have no use for any of the controls. Is there a benefit of using Control.BeginIn voke opposed to ThreadPool.Queu eWorkItem? From the threads I have briefly scanned over on the www, there really is no difference other. Some have mentioned that ThreadPool.Queu eWorkItem maybe faster, but thats about all. Any thoughts?
> Now, when you call BeginInvoke, it will call Invoke on another thread of execution, through QueueWorkItem, but the call ultimately will end up being called on the thread that created the control. It's just that you don't have to wait for Invoke to return on the thread you call BeginInvoke on.
This is incorrect.
BeginInvoke uses the PostMessage API to put the message asynchronously to
the other thread. The PostMessage API queues the message and returns.. (so
in general you are queuing either way).
If I remember correctly, Invoke actually does the same thing but blocks
until it has a response although I believed it called SendMessage at some
point in history.
Just to be clear ...
Cheers,
Greg Young
MVP - C#
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:uU******** ******@TK2MSFTN GP04.phx.gbl... RWF,
The question one has to ask is, to what end are you doing this?
These things are actually very different.
Control.BeginIn voke/Invoke will cause the delegate passed to it to be executed on the thread that calls need to be synchronized on. Windows controls require changes to them to be executed on the thread that created them. When you call BeginInvoke/Invoke, it makes sure that the call is marshaled correctly.
When you call QueueWorkItem, a method is executed on another thread of execution.
Now, when you call BeginInvoke, it will call Invoke on another thread of execution, through QueueWorkItem, but the call ultimately will end up being called on the thread that created the control. It's just that you don't have to wait for Invoke to return on the thread you call BeginInvoke on.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"RWF" <RW*@discussion s.microsoft.com > wrote in message news:3D******** *************** ***********@mic rosoft.com...I have a windows form of which I will be saving the user's selections from DropDownBoxes, CheckBoxes, and RadioButtons. Once the choices are collected, I really will have no use for any of the controls. Is there a benefit of using Control.BeginIn voke opposed to ThreadPool.Queu eWorkItem? From the threads I have briefly scanned over on the www, there really is no difference other. Some have mentioned that ThreadPool.Queu eWorkItem maybe faster, but thats about all. Any thoughts?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: fred |
last post by:
I'm writing an application invoking asynchon methods.
I envision using the .NET thread pool since it matches
well my needs.
There is (at least) 2 methods to do that:
using ThreadPool class directely or using the BeginInvoke
() of a delegate.
Does anybody knows any advantages from one method to
|
by: Henri |
last post by:
Might sound a stupid question but need to be sure:
When you call ThreadPool.QueueUserWorkItem and
ThreadPool.RegisterWaitForSingleObject passing a New object as state
e.g.: ThreadPool.QueueUserWorkItem(AddressOf MyCallBack, New
MyObject(myArg1, myArg2))
the new object MyObject is instantiated just before QueueUserWorkItem is
called, and not just before MyCallBack is called, isn't it?
|
by: pmclinn |
last post by:
In the code format below, is there any way to pass in a variable to the
writefiles proceedure?
ThreadPool.QueueUserWorkItem(AddressOf WriteFiles)
Public Sub WriteFiles(ByVal stateInfo As Object)
End Sub
|
by: john doe |
last post by:
I have a question about BeginInvoke method found on the Control class.
To quote the docs:
"Executes the specified delegate asynchronously with the specified
arguments, on the thread that the control's underlying handle was
created on."
Which is fine, but I'm wondering how does this method get called
asynchronously if it's on the same thread we are working on? Surely it
blocks the thread until returned?
|
by: Dean Shimic |
last post by:
void DisplayLines(object state)
{
for (int i = 0; i < 500; ++i)
{
int iCopy = i;
rtb.BeginInvoke((MethodInvoker)delegate
{
rtb.AppendText(iCopy + "\n");
});
}
| |
by: Bharathi |
last post by:
Hi,
Iam working in windows appln using .NET framework 2.0.
My application is having several threads running.
All threads can call a common method.
|
by: Flack |
last post by:
Hello,
If I understand BeginInvoke correctly, when it is called your delegate is
run on a thread pool thread. Now, if you supplied a callback delegate, that
too is called on the same thread pool thread.
My question is this: Do I ever need to check the value of InvokeRequired in
my callback method before working with some GUI controls? Won't it always be
required since the callback is running on a thread pool thread? I see some
code...
|
by: robparr |
last post by:
Hello, hopefully someone can help me.
I am reading and learning steadily about threading and asynchronous
programming, which to me sound like the same thing. At the moment I am
not sure what the difference is between using ThreadStart and
delegates instead of using BeginInvoke. Can both of them be used to
achieve the same thing? Or perhaps you should use one over the other?
I am slightly confused because I was looking at this example...
|
by: robert112 |
last post by:
Question... Can one not use ThreadPool.QueueUserWorkItem with an
anonymous method like so:
ThreadPool.QueueUserWorkItem(delegate
{
//perform IO bound operation.
});
Why did the asp.net team create the directive async=true way of
creating async pages???
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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: 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: 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: 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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |