Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C# Coding - Delegate and Event Setup

Status
Not open for further replies.

ama_trig

Full Member level 2
Joined
Oct 9, 2009
Messages
123
Helped
20
Reputation
40
Reaction score
13
Trophy points
1,298
Location
Where my hard drive lives!
Activity points
2,100
Code:
Class A
{
	
	ButtonClick()
	{
		//SomeVariable
		//SomeCode

		***According to SomeVariable, set callback of Class B's Method_1 to
		*** UpdataA Method or UpdateB Method or anything else defined here 
		***(not written in Method_1 code block, so it can be changed from here)
			Something like this :
			Call ClassB.Method2(timer_interval,Method_UpdateA_ResultOfMethod1)
			or 
			Call ClassB.Method2(timer_interval,Method_UpdateA_ResultOfMethod2)
	}

	Method_UpdateA_ResultOfMethod1(string INPUT)
	{
		//some code
		//Display Input
	}

	Method_UpdateB_ResultOfMethod1(string INPUT)
	{
		//some code
		//Display Input
	}
}

Class B
{
	Method_1()
	{
		//some code
		How to callback to Class A method (predefined by method 2) and pass an argument?
	}
	
	Method_2(?)
	{
		//Install Timer On method 1 that triggers every second
		How to set a callback to One of methods of Class A ?
	}
}
No matter how much I try, I couldn't make it work, it seems fairly easy in c using function pointer, but in c# I'm stock.
So far what I've read is that an event and delegate must be used, But I couldn't make it work, I think this is because I don't understand anonymous delegates, event, ... well enough.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top