Why are out parmeters included in an BeginInvoke? They seem to do
nothing?
TestProgam:
using System;
namespace TempConsole {
class App {
public delegate void MyDelegate( out byte b, out string s );
public static void OnMyDelegate( out byte b, out string s ) {
b = 10;
s = "Changed by Delegate.";
}
static void Main( string[] arg s) {
MyDelegate md = new MyDelegate( OnMyDelegate );
byte b1 = 1;
string s1 = "Unchanged by Delegate.";
IAsyncResult ar = md.BeginInvoke( out b1, out s1, null,
null);
ar.AsyncWaitHan dle.WaitOne();
byte b2 = 2;
string s2 = "Will be changed by Delegate.";
md.EndInvoke(ou t b2, out s2, ar);
Console.WriteLi ne( "BeginInvok e out arguments: {0}, {1}",
b1, s1 );
Console.WriteLi ne( "EndInvoke out arguments: {0}, {1}",
b2, s2 );
Console.ReadLin e();
}
}
}
Results:
BeginInvoke out arguments: 1, Unchanged by Delegate.
EndInvoke out arguments: 10, Changed by Delegate. 4 2370
Hi Jon,
Although we should use out parameters for output proposes only, but
technically they can be used as ref parameters to supply inputs if necessary
but that is not recomended for some reasons (can tell if interested).
so, as long as they can supply input, they included in BeginInvoke, but the
actual modifed parameters which get the output results will be accessed via
EndInvoke.
--
Ahmed Ghozzy
"Jon" wrote: Why are out parmeters included in an BeginInvoke? They seem to do nothing?
TestProgam:
using System;
namespace TempConsole { class App { public delegate void MyDelegate( out byte b, out string s );
public static void OnMyDelegate( out byte b, out string s ) { b = 10; s = "Changed by Delegate."; }
static void Main( string[] arg s) { MyDelegate md = new MyDelegate( OnMyDelegate ); byte b1 = 1; string s1 = "Unchanged by Delegate."; IAsyncResult ar = md.BeginInvoke( out b1, out s1, null, null);
ar.AsyncWaitHan dle.WaitOne();
byte b2 = 2; string s2 = "Will be changed by Delegate."; md.EndInvoke(ou t b2, out s2, ar);
Console.WriteLi ne( "BeginInvok e out arguments: {0}, {1}", b1, s1 ); Console.WriteLi ne( "EndInvoke out arguments: {0}, {1}", b2, s2 ); Console.ReadLin e(); } } }
Results: BeginInvoke out arguments: 1, Unchanged by Delegate. EndInvoke out arguments: 10, Changed by Delegate.
I can not access the out parameters before OnMyDelegate initializes
them. So I can not see how they can supply input.
public static void OnMyDelegate(ou t byte b, out string s) {
//Console.WriteLi ne( "OnMyDelega te arguments: {0}, {1}", b,
s ); //This does not compile
b = 10;
s = "Changed by Delegate.";
}
I believe they could supply inputs in v1.0 because i used it as i remember,
and it is quite sure for me that supplying input for out param in v1.1 is not
useful anymore just like you discovered, but it seems that BeginInvoke still
as it was since v1.0 .
if BeginInvoke requirment of out paramters bother you, you can supply nulls
in them and get the true putput from EndInvok
--
Ahmed Ghozzy
"Jon" wrote: I can not access the out parameters before OnMyDelegate initializes them. So I can not see how they can supply input.
public static void OnMyDelegate(ou t byte b, out string s) { //Console.WriteLi ne( "OnMyDelega te arguments: {0}, {1}", b, s ); //This does not compile
b = 10; s = "Changed by Delegate."; }
I guess the rules (at least for v1.1) are:
BeginInvoke() 'out parameters' are ignored.
EndInvoke() 'ref parameters' are really output only. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Grandma Wilkerson |
last post by:
My question concerns the documentation for Control.BeginInvoke(). At one
point is says:
"Executes the specified delegate asynchronously with the specified
arguments, on the thread that the control's underlying handle was created
on."
later in that same documentation page it says...
"Note The BeginInvoke method calls the specified delegate back on a
|
by: arkam |
last post by:
Hi,
I found a sample on internet :
formMain.BeginInvoke(new MyClickHandler(this.OnMyClick));
I would like to do the same but in a class library where there is no forms !
Where can I find a BeginInvoke equivalent for a class library ?
|
by: David Sworder |
last post by:
Hi,
I have a form that displays data (is that vague enough for you?). The
data comes in on a thread-pool thread. Since the thread pool thread is not
the same as the UI thread, the callback function of my form follows the
standard design pattern:
if(IsDisposed){
return;
}
|
by: Valerie Hough |
last post by:
I'm not entirely sure what the difference is between these two approaches.
In order to avoid reentrant code, I was using Control.BeginInvoke in my UI
to cause an asynchronous activity to be done on the UI's message loop. I
began to get System.ExecutionEngineException errors so (on the theory of do
something different if what you're doing isn't working) I switched to using
delegate.BeginInvoke with the appropriate EndInvoke and the problem...
|
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: RWF |
last post by:
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.BeginInvoke opposed to ThreadPool.QueueWorkItem? From the
threads I have briefly scanned over on the www, there really is no difference
other. Some have mentioned that ThreadPool.QueueWorkItem maybe...
|
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: =?Utf-8?B?a2VubmV0aG1Abm9zcGFtLm5vc3BhbQ==?= |
last post by:
vs2005, c#
Trying to understand why one way works but the other doesnt.
I have not tried to create a simpler mdi/child/showdialog app for posting
purposes (I think even this would not be so small or simple). I am hoping
the description will generate some ideas I can check out.
PROBLEM:
-----------------
Switching to UI thread using Invoke(), everything seems good.
|
by: Ben Voigt [C++ MVP] |
last post by:
As much as the CLR team assures us that it's ok to fire-and-forget
Control.BeginInvoke, it seems it isn't. Maybe this is a bug.
See for example: the comments in
http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx
I was encountering a bug that disappeared when debugging. Not when a
debugger is attached, mind you, but when I placed a breakpoint near the
code. Adding Trace.WriteLine statements showed that the failing code was...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |