1 2 3 4 5 6 7 8 9 10 |
public Form1() { System.Net.WebClient wc = new System.Net.WebClient(); wc.DownloadStringCompleted += (s, e) => { MessageBox.Show("done"); }; wc.DownloadStringAsync(new Uri("https://www.google.co.jp")); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
BackgroundWorker w = new BackgroundWorker(); public Form1() { InitializeComponent(); // xxxAsyncで実行、終了時にxxxCompletedのコールバック // BackgroundWorkerが標準でサポート w.DoWork += OnWork; w.RunWorkerCompleted += OnWorkCompleted; w.RunWorkerAsync(); MessageBox.Show("end"); // 待機がないとcompletedが表示される前にメインスレッドが終了する } private void OnWork(object sender, DoWorkEventArgs e) { MessageBox.Show("work"); } private void OnWorkCompleted(object sender, RunWorkerCompletedEventArgs e) { MessageBox.Show("completed"); } |
対応している型
System.ComponentModel.Component
System.ComponentModel.BackgroundWorker
System.Media.SoundPlayer
System.Net.WebClient
System.Net.NetworkInformation.Ping
System.Windows.Forms.PictureBox
System.Net.Mail.SmtpClient
System.Deployment.Application.ApplicationDeployment
System.Deployment.Application.InPlaceHostingManager
System.Activities.WorkflowInvoker
System.ServiceModel.Activities.WorkflowControlClient
System.Net.PeerToPeer.PeerNameResolver
System.Net.PeerToPeer.Collaboration.ContactManager
System.Net.PeerToPeer.Collaboration.Peer
System.Net.PeerToPeer.Collaboration.PeerContact
System.Net.PeerToPeer.Collaboration.PeerNearMe
System.ServiceModel.Discovery.AnnouncementClient
System.ServiceModel.Discovery.DiscoveryClient