在C#中完成/处理模式
IDisposable
using(myClass objClass = new myClass()){
// Do stuff here}public class NoGateway : IDisposable{
private WebClient wc = null;
public NoGateway()
{
wc = new WebClient();
wc.DownloadStringCompleted += wc_DownloadStringCompleted;
}
// Start the Async call to find if NoGateway is true or false
public void NoGatewayStatus()
{
// Start the Async's download
// Do other work here
wc.DownloadStringAsync(new Uri(www.xxxx.xxx));
}
private void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
// Do work here
}
// Dispose of the NoGateway object
public void Dispose()
{
wc.DownloadStringCompleted -= wc_DownloadStringCompleted;
wc.Dispose();
GC.SuppressFinalize(this);
}}using(NoGateway objNoGateway = new NoGateway()){
// Do stuff here }NoGateway objNoGateway = new NoGateway();// Do stuff with objectobjNoGateway.Dispose(); // finished with it
NoGateway
慕田峪4524236
达令说
随时随地看视频慕课网APP