问题
I have some codes that i find very hard to understand. Can someone help me break it down line by line?
Service1Client client = new Service1Client();
client.getPrimaryListCompleted += new EventHandler<getPrimaryListCompletedEventArgs>(AddPrimaryMarkerGraphics);
client.getPrimaryListAsync();
回答1:
The first line creates an instance of the class Service1Client.
The second line hooks up an event handler for the event getPrimaryListCompleted.
the third line starts an asynchronous request. When there is a response, the getPrimaryListCompleted will be triggered so that the event handler can use the response.
回答2:
- Create a new
ServiceClientcalled client. - Add an event handler to client so that when Primary List Function is completed the function
AddPrimaryMarkerGraphicsis automatically called. - Call the client function
getPrimaryListAsync()(Async means that this function will be executed asynchronously ie: on another thread)
回答3:
This Service1Client client = new Service1Client(); creates a new object of type Service1Client() which presumably is a client for calling a WCF service.
Then is attaches an event handler which will get called when the client raises the specified event.
The last line starts an asynchroneous service call (means its running in the background on a separate thread). Once that call has completed it probably raises the getPrimaryListCompleted event so the event handler will be called.
来源:https://stackoverflow.com/questions/5974789/help-with-explanation