471,582 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Why are out parmeters included in an BeginInvoke ?

Jon
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.AsyncWaitHandle.WaitOne();

byte b2 = 2;
string s2 = "Will be changed by Delegate.";
md.EndInvoke(out b2, out s2, ar);

Console.WriteLine( "BeginInvoke out arguments: {0}, {1}",
b1, s1 );
Console.WriteLine( "EndInvoke out arguments: {0}, {1}",
b2, s2 );
Console.ReadLine();
}
}
}

Results:
BeginInvoke out arguments: 1, Unchanged by Delegate.
EndInvoke out arguments: 10, Changed by Delegate.

Nov 17 '05 #1
4 2263
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.AsyncWaitHandle.WaitOne();

byte b2 = 2;
string s2 = "Will be changed by Delegate.";
md.EndInvoke(out b2, out s2, ar);

Console.WriteLine( "BeginInvoke out arguments: {0}, {1}",
b1, s1 );
Console.WriteLine( "EndInvoke out arguments: {0}, {1}",
b2, s2 );
Console.ReadLine();
}
}
}

Results:
BeginInvoke out arguments: 1, Unchanged by Delegate.
EndInvoke out arguments: 10, Changed by Delegate.

Nov 17 '05 #2
Jon
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(out byte b, out string s) {
//Console.WriteLine( "OnMyDelegate arguments: {0}, {1}", b,
s ); //This does not compile

b = 10;
s = "Changed by Delegate.";
}

Nov 17 '05 #3
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(out byte b, out string s) {
//Console.WriteLine( "OnMyDelegate arguments: {0}, {1}", b,
s ); //This does not compile

b = 10;
s = "Changed by Delegate.";
}

Nov 17 '05 #4
Jon
I guess the rules (at least for v1.1) are:

BeginInvoke() 'out parameters' are ignored.

EndInvoke() 'ref parameters' are really output only.

Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Grandma Wilkerson | last post: by
9 posts views Thread by David Sworder | last post: by
6 posts views Thread by Valerie Hough | last post: by
9 posts views Thread by john doe | last post: by
3 posts views Thread by RWF | last post: by
2 posts views Thread by Flack | last post: by
2 posts views Thread by =?Utf-8?B?a2VubmV0aG1Abm9zcGFtLm5vc3BhbQ==?= | last post: by
7 posts views Thread by Ben Voigt [C++ MVP] | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Vinnie | last post: by
1 post views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

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.