이 코드는 사용자가 인증 서버의 응답을 기다리는 로그인 양식의 일부입니다.
using System;
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;
namespace LoginWithProgressBar
{
public partial class TheForm : Form
{
private readonly BackgroundWorker _bw = new BackgroundWorker();
public TheForm()
{
InitializeComponent();
progressBar.MarqueeAnimationSpeed = 30;
progressBar.Visible = false;
_bw.DoWork += Login;
_bw.RunWorkerCompleted += BwRunWorkerCompleted;
}
private void BwRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
progressBar.Hide();
}
private static void Login(object sender, DoWorkEventArgs doWorkEventArgs)
{
Thread.Sleep(3000);
}
private void ButtonLoginClick(object sender, EventArgs e)
{
progressBar.Show();
_bw.RunWorkerAsync();
}
}
}