Join Dotnetcodes DotnetCodes.com is online Discussion Forum for Software professionals . It lets you find friends around the world and Create professional network that share similar interests as you. Get help on ur projects by industry specialists. Also get answers to all ur technical/placement related querries.Get an edge over others.
Already MemberClick here to login
ASP.net MVC Interview Questions Answers Interview Questions
Get Started Developing for Android Apps with Eclipse Articles
Serial Number in SSRS Articles
.Net framework 4.0 Interview Questions Answers Interview Questions
SQL server reporting services Interview Questions (SSRS) part 1 Articles
Whats New in ASP.NET 4.0 Part 2 Articles
How to Print a Crystal Report direct to printer Articles
Difference between Encapsulation and Abstraction Interview Questions
Explaining SDLC -System Development Life Cycle Articles
Html5 interview questions and answers Interview Questions
SharePoint 2010 interview Questions Answers Interview Questions
Infosys Interview Questions Interview Questions
Dynamic Menu using HTML List Tag and CSS in ASP.Net Articles
Populate or bind Dropdownlist in Asp.net using Jquery and Json Articles
ASP.NET MVC Overview Interview Questions
Submit Articles | More Articles..

in which scenario should use Delegate in C#?

Posted By: Jaishree on 9/3/2010 4:55:49 AM | Comments:1 [Forward This]
HI, I want to know, any scenario or example where i can use delegate to call a method at runtime. Till now i did not feel any need to call a method runtime. so please elaborate this concept. Thanks in Advance.
Read CommentsComments Category:CSharp Reply to this PostReply

Dear Friends, Dont forget to bookmark and submit your posting to social websites listed above.It will bring more visibility, buzz and fast action to attend your post

Responses to the Discussion: in which scenario should use Delegate in C#?
Reply by: rakesh on: 9/3/2010 5:37:15 AM
Hi, below are the situation where u should use Delegates. 1. If you want to create a event and want to run different methods, on different scenarios. 2. If you want to run multiple methods in response to a single event. 3. Callback mechanism - If you are developing a component(asynchronous) which needs to send an alert to the caller after it s completion, then you need to know the caller s alert function (which is not feasible in real time). So to overcome that, caller should send some function pointer (i.e. delegate) to the component, to call it back after the task. You will always use a delegate to respond to an event. An event is a trigger mechanism, but it s the delegate that satisfies it. Even when you use the += notation, you are implicitly wrapping a member as a delegate and passing it to the event. There are plenty of times when delegates make sense. In command binding, for example, the ICommand interface has an "execute" and a "canexecute" method. You could do a separate implementation for every scenario, or you can use the DelegateCommand pattern that simply allows you to inject functionality to execute and determine if you "can execute." When simplifying services, you most likely do NOT want to expose the asynchronous call structure to the rest of your application because of the overhead. A simple way to abstract this is to pass in a callback delegate to your service layer, wait for the service call to complete, and call back. If you are programming in WPF or Silverlight, there are many times you have work done on a separate (background) thread that must update the UI. In that scenario, the values must be marshalled to the dispatcher or main UI thread. This is done by passing the action as a delegate to the thread.
 
You have not Logged In,  click here to Login
Reply Here
 
, I agree the terms and conditions of this website
  
  .NET Framework
  ADO.NET
  AJAX
  Android
  ASP.NET
  ASP.NET AJAX
  ASP.NET MVC
  Azure
  Best Practices
  BizTalk Server
  C++
  CSharp
  CSS
  DBMS
  Error and Resolution
  HTML
  IIS
  JAVA
  JavaScript
  JQwery
  JSP
  LINQ
  Management
  Mobile
  ODP.NET
  OOPS
  Oracle
  Others
  Pattern and Practices
  PHP
  SAP
  SEO
  SharePoint
  Silverlight
  Sql Server
  SSAS
  SSIS
  SSRS
  Survey
  UML
  UNIX
  VB
  VB.NET
  VS 2010
  WCF
  Web Analytics
  Windows Forms
  WPF
  WWF
  XML
  XSLT
  .NET Framework
  ADO.NET
  AJAX
  Android
  ASP.NET
  ASP.NET AJAX
  ASP.NET MVC
  Azure
  Best Practices
  BizTalk Server
  C++
  CSharp
  CSS
  DBMS
  Error and Resolution
  HTML
  IIS
  JAVA
  JavaScript
  JQwery
  JSP
  LINQ
  Management
  Mobile
  ODP.NET
  OOPS
  Oracle
  Others
  Pattern and Practices
  PHP
  SAP
  SEO
  SharePoint
  Silverlight
  Sql Server
  SSAS
  SSIS
  SSRS
  Survey
  UML
  UNIX
  VB
  VB.NET
  VS 2010
  WCF
  Web Analytics
  Windows Forms
  WPF
  WWF
  XML
  XSLT
All rights reserved to dotnetcodes. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
Best viewed at 1024 x 768 resolution with Internet Explorer 5.0 or Mozila Firefox 3.5 or Google Crome and higher