[C# Simple Callback] C# 의 정말 간단한 콜백 호출방법

as3 를 예로 들자면 콜백작성이 매우 자유롭다 이유는 Function 형이 존재하기 때문이다.

ex> var someMethod : Function
someMethod()

처럼 변수처럼 선언하였다가 변수를 원할때는 '()' 를 빼줬다가 메소드를 원할때는 '()'를 붙이기만 하면 된다.
 c# 은 이러한 나이스한 방법이 다소 제한된다.
교과서 적인 콜백을 보자면, 정석적인 이벤트 선언이나, 기본 api에서 제공하는 콜백을 사용하는 경우를 무수히 볼수 있다.
하지만 더욱 간편하고 as3 의 표현과 같은 느낌으로 사용하는 법을 한번 보자 정말 심플한 콜백 사용법이다.





public
partial class Form1 : Form { public Form1() { InitializeComponent(); //콜백테스트 클레스 선언 , 생성 CallBackTEST callbackTest = new CallBackTEST(); callbackTest.onComplete(complete); } //CallBackTEST 클레스에서 선언한 delegate 형식에 맞추어 int 변수 하나를 받는 메소드 작성 private void complete(int count) { Console.WriteLine("callback complete" + count); } } class CallBackTEST { //콜백을 전달할 delegate 선언 (인수 전달/) public delegate void onCompleteDele(int i); // 테스트 :: // 타이머가 시작작고 count가 2가 되었을때 콜백! // onComplete 의 매개변수 _callCompleteMethod 의 형식은 앞서 선언한 "onCompleteDele" 이다 public void onComplete(onCompleteDele _callCompleteMethod) { Timer t = new Timer(); t.Interval = 1000; t.Start(); int count = 0; t.Tick += delegate { if (count == 2) //!!콜백발생 _callCompleteMethod(count); ++count; }; } }
 
물론 as3 보다 복잡하긴 하지만 델리게이트를 선언함으로서 비동기 , 동기 처리가 가능하고 , 
인자를 넘기는것도 비교적 단순하다.
그리고 정말 장점은 콜백을 받는 메소드의 인텔리센스를 얻을수 있어 as3와 다르게 실수에 의한 런타임 에러를 방지할수 있다. 
Yamecoder 야매코더_
C# 2011. 1. 6. 00:57

댓글을 달아 주세요

  1. 이전 댓글 더보기
  2. BlogIcon discount furla handbags 2015.01.08 23:11  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  3. BlogIcon furla bags online 2015.01.09 06:45  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  4. 匿名 2015.01.14 18:27  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  5. BlogIcon woolrich coats 2015.01.20 21:09  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  6. BlogIcon furla tote bag 2015.01.31 14:00  수정/삭제  댓글쓰기

    드습Square One merchant ordered to stand trial on sex charges

    MISSISSAUGA A Mississauga man who owns a collectibles store at Square One Shopping Centre has been ordered to stand trial on multiple charges of sexual assault and sexual exploitation.

    Justice June Maresca ruled at the end of today's preliminary hearing in Brampton court that there is enough evidence to send Manfred Goetz, 55, to tria습수

  7. BlogIcon furla purses on sale 2015.02.04 13:34  수정/삭제  댓글쓰기

    메마Inflation a sizable get worried regarding small enterprise

    NEW YORK Don't be misled via evaluations that inflation is really obtain. Regarding smaller businesses, it's a danger to be able to income in addition to development applications.

    A great 8 % enhance inside the buying price of ovum within the last 12 several weeks is really eating apart from eating places in addition to bakeries. Cot수에

  8. BlogIcon mont blanc pens 2015.02.18 23:10  수정/삭제  댓글쓰기

    서가'The Tale associated with Wangfried Knobblestone'

    Many years back, a guy called Wangfried Knobblestone grew to become gran of the pleased small city known as Taffetta.

    He or she had been aged, old and wrinkly as well as hunchbacked. Their the teeth had been yellow-colored as well as he'd lengthy finger nails. He or she had been miserly, money grubbing as well as vicious as well as might glee및방

  9. BlogIcon mont blanc pens 2015.02.20 13:58  수정/삭제  댓글쓰기

    있마How you can Printing upon Steel,gucci sneakers

    Choose to make use of an additional technique in case your inkjet printer will not printing upon pulsating. Buy a few ink jet move linens which will focus on steel. Linens such as Lazertran state they'll printing on to any kind of materials. [1]Load the actual exchanges to the inkjet printer. Your woman had been snapped up through the wikiSpirit th습지

  10. 匿名 2015.03.01 14:22  수정/삭제  댓글쓰기

    다습大话西游服务端凡人修真服务端大话西游服务端页游服务端问道服务端

    跑跑卡丁车服务端英雄远征服务端幻灵游侠私服务端洪荒神话私服务端

    完美世界服务端烈焰服务端洛汗服务端新魔界服务端绝对女神私服务端


    魔兽私服开区一条龙服务-

    传奇私服开传奇一条龙服务-


    传奇广告代理-

    IDC服务器以及空间租用-

    魔域开区sf一条龙开区服务-


    客服咨询QQ(企鹅扣扣)1325876192

    Email:1325876192@qq.com

    商业版本免费开放下载




    紫川科技最新毁灭天下1.85狂雷独家合击热血复古三职业新装传奇服务端



    紫川科技20星大极品良装+80麒麟锻造中变传奇服务端



    紫川科技独家轻变1.89奥妙转生神龙锻造珍珑元素版传奇服务端



    紫川科技独家九转1.85四皇冠加倍装备特戒龙卫상뉴

  11. BlogIcon tiffany co sunglasses 2015.03.05 17:04  수정/삭제  댓글쓰기

    런할you will take a look at camping for the basictime. you do not seem to make sure what to bring and the way to pack. the next guide will allow you to feel secure and well-prepared. Spring is a trickytime to camp. For something, the elements is unpredictable. you could have mild, sunny days with morning cold. you can also encounter spring showers. you are going to be prepared for all and any weather.메데

  12. BlogIcon gucci sneakers 2015.03.07 16:31  수정/삭제  댓글쓰기

    간가Whats on in Brighton on Thursday 19 Feb 2015

    Using body isolations to express music, Tribal Fusion is an eclectic dance style combining elements of street dance, flamenco and contemporary dance. Dynamic movement from liquid undulations to sharp hip drops are characteristic to this unique style.

    Brighton Hove High School

    Check In and Like our Facebook page throughout February each time you지할

  13. BlogIcon woolrich coats men 2015.03.18 01:01  수정/삭제  댓글쓰기

    선니tights clothes solved

    100 % cotton leggings tend to be furla online simple to find everywhere, however many of them would be the heavy, cumbersome, jacket b types that we do not would like. We accustomed to purchase a type known as "light cotton" or even "thin cotton" through chanel handbags wholesale Solution through Zellers that we furla bags online cannot discover any longer. These were main비리

  14. BlogIcon oakley sunglasses 2015.03.20 11:08  수정/삭제  댓글쓰기

    마지Asus announces brand new ZenWatch wearable

    The actual ZenWatch, created together with Search engines, includes a bent cup style along with a situation which made to adhere to the actual curves of the arm,oakley sunglasses, together with reasonably limited leather-based straps.

    When it comes to specs, the actual ZenWatch sports activities the 1. 2GHz Snapdragon four hundred processor chip,lou마데

  15. BlogIcon cheap oakley sunglasses 2015.03.26 02:09  수정/삭제  댓글쓰기

    비법Best Handbags For Women That Love Designer Handbags

    While designer purses are sometimes recognized for his or her sophisticated look, carrying them will also be fun. Up to date appears to be like function brighter colours and more shine to make bold style statements. Producers recognize that you've got shelled out large bucks for designer purses and know you deserve to get noticed.

    A new pat지지

  16. BlogIcon furla candy bag 2015.03.29 14:59  수정/삭제  댓글쓰기

    리일Delivery Man Watch Online Free

    Apart from the Watch Delivery Man online free failed humor (as when Dave pretends not to be able to speak English when michael kors stores a lawyer visits him burberry outlet in his residence), Delivery Man's perhaps most obviously failing may be the clumsy way in which Dave's "encounters" with his children are usually orchestrated. The contrivances infecting thes로니

  17. BlogIcon trench coat burberry 2015.03.31 00:03  수정/삭제  댓글쓰기

    지마des matières fécales, des engrais, de sorte que le Gouvernement ne peut pas supporter? les habitants de plusieurs villes du Brésil dans les rues pour exprimer le mécontentement.李思源 周野 Fujian Xiamen rapportés相关的主题文章: à 22 h 30,Il a dit que l'Asie est la puissance économique important dans le monde,chaussure burberry pas cher, doit jouer un rle plus i일어

  18. BlogIcon sac louis vuitton pas cher 2015.04.04 19:55  수정/삭제  댓글쓰기

    뉴들Supreme Court bid over DNA evidence

    Kevin Nunn was convicted in 2006 of the louis vuitton outlet murder of Dawn Walker after her partially clothed body was found on the bank of the louis vuitton outlets River Lark in Suffolk, but he claims he is innocent.

    Nunn's legal team are trying to force Suffolk Police to give them access to key forensic evidence linked to the case that they said was no에니

  19. 匿名 2015.04.08 09:20  수정/삭제  댓글쓰기

    이리presents the visible face of cloud computing that most people have already experienced. The advantages of web-based applications such as Gmail, Twitter, and Facebook are pretty obvious - there's nothing to download to your PC, you can access them from anywhere, they're constantly being enhanced and every time updates are made they become instantly available to any user when they next login.



    하다

  20. BlogIcon furla purses 2015.04.09 20:36  수정/삭제  댓글쓰기

    려스If anything that early edition of Jabba was missing one thing: Oola, his slave dancer. In 1998 Oola would finally get her own figure in a fan club exclusive. Jabba, on the other hand,louis vuitton online outlet, would take a turn for the worse with his Special Edition rendition.

    The holiday season is round the corner and all of us do some amount of travelling every year. Even if you haven't pla메및

  21. BlogIcon discount oakley sunglasses 2015.04.13 01:23  수정/삭제  댓글쓰기

    리없bedsheets along with other 'suspicious packages'

    Final Xmas,oakley sunglasses, under garments explosive device believe Umar Farouk Abdulmutallab presumably attempted in order to fire up the dubious bundle he would smuggled within their trousers on to the aircraft sure with regard to Detroit. A few had been actual hazards, like the bundle bombs in the Switzerland as well as Chilean Embassies wit있련

Powerd by Tistory, designed by criuce
rss