473,394 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

pass delegate as arg to method?

VM
How can I pass a delegate to another method? In my code (win app), i update
my datagrid with the datatable after the method loadAuditFileToTable is
finished executing. Instead, I'd like to be able to to update the grid
continuously (while the table's filling) and someone suggested I pass a
callback to loadAuditFileToTable and run it every X records. How can I do
this? This is a summary of my code:

loadAuditFileToTableDelegate LoadAuditFileToTable = new
loadAuditFileToTableDelegate(loadAuditFileToTable) ;
LoadAuditFileToTable.BeginInvoke (new AsyncCallback(yourCallback), null);

delegate void GUIUPdate();
void yourCallback(IAsyncResult iar)
{
if (iar.IsCompleted)
{
dataGrid_auditAddress.Invoke (new GUIUPdate(guiUpdateMethod),null);
}
}
private void guiUpdateMethod()
{
this.dataGrid_auditAddress.DataSource = _table_auditAddress;
}
private void loadAuditFileToTable()
{
ZMMatch.Audit zmAudit = new ZMMatch.Audit(NONE, NONE);
_table_auditAddress = zmAudit.OpenAuditAZMFileToView(_SFileName);
//takes some time to complete
}
public DataTable OpenAuditAZMFileToView(string sFileName)
{
/* ZMMatch class
// open file, create table/columns,etc...
sAuditRecord = sr.ReadLine();
while (sAuditRecord != null)
{
/* Parse/process line, fill row, and add row to table. Loop will add
500,000 rows */
sAuditRecord = sr.ReadLine();
}
return myTable;
Nov 16 '05 #1
1 1780
VM <vo******@yahoo.com> wrote:
How can I pass a delegate to another method?


Just declare it as one of the parameters. For instance:

using System;

delegate void DoSomething();

class Test
{

static void Main()
{
Foo (new DoSomething(SayHi));
}

static void Foo(DoSomething wibble)
{
wibble();
}

static void SayHi()
{
Console.WriteLine("Hi");
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: yoramo | last post by:
hello can I pass a static method as a parameter to a method? if the answer is yes how do I do that ? how do I call the method ? yoramo.
4
by: Gopal Prabhakaran | last post by:
Pls Help me - Asap public void start(delegate wm,string name) - is this possiable ? if so Pls tell me how to do? r - give some sample codes? r - tell me some sites to learn?
6
by: Tee | last post by:
Hi, Can anyone tell me if it's possible to pass a method to another class? Example of what I would like to do: class1: public void MyMethod() {
4
by: KC Eric | last post by:
Hi all, I have a dll file, it has a class, say: class Temp, this class has a function which has a delegate as a parameter, say: public void Test(GameOverHandler _overHandler)
0
by: verpeter | last post by:
When try pass only one delegate as parameter, all work fine. But I need call function, that take as parameter array of function pointers. From C++ code I used such code: static void* aFuncPtrs =...
3
by: Bob Speaking | last post by:
Hi at all, Is possible to pass a parameter though a delegate or to override it? (I'm newbie and I'm trying to understand delegates and their use in a real scenario) In my scenario I need to...
3
by: John Dalberg | last post by:
I have seen examples for List<T>.FindAll(findthis)where findthis is a predicate. How do I pass a parameter to this predicate so that I have different values to search for? I don't want to use...
2
by: Curious | last post by:
I have a C#.NET program that uses a delegate, "BuildExistingReportFile". It's called in such a fashion: IList lFiles = this.GetListFromStoredProcedure( null,...
6
by: =?Utf-8?B?emlubw==?= | last post by:
I'm trying to pass a delegate as parameter but the code below does not compile. It display an error: 'AddressOf operand must the name of a method(without parantheses)' How can I make it work. ...
24
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
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,...
0
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...

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.