로그인 양식을 만들려고합니다. 내가 가지고있는 문제는 로그인 프로세스가 너무 오래 걸리고 내 GUI를 잠그고 있다는 것입니다. 나는 백그라운드 작업자에 대해 읽었지만, 내 프로그램이 로그인 프로세스를 기다리는 방법에 대해서는 여전히 불확실하지만 내 GUI는 동결하지 않습니다. 더 자세히 설명하는 데 도움이되는 코드는 다음과 같습니다.GUI가 멈추는 것을 방지하는 방법에 대한 질문은 있지만 차단 된 상태로 유지하십시오.
Login.cs
public partial class Login : Form
{
public delegate bool Authenicate(string account, string password,string type);
public Authenicate authenicate;
public Login()
{
InitializeComponent();
}
private void btnLogin_Click(object sender, EventArgs e)
{
if (txtAccount.Text == string.Empty)
{
MessageBox.Show("Must include account number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (txtPassword.Text == string.Empty)
{
MessageBox.Show("Must include password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!authenicate(txtAccount.Text, txtPassword.Text,cmbType.Items[cmbType.SelectedIndex].ToString()))
{
return;
}
this.DialogResult = DialogResult.OK;
}
private void Login_Load(object sender, EventArgs e)
{
cmbType.SelectedIndex = 0;
}
MainForm.cs
public partial class MainForm: Form
{
Ex.Service myService=new Ex.Service();
public MainForm()
{
InitializeComponent();
}
public bool Authenicate(string account, string password,string type)
{
try
{
//Login takes too long and locks up GUI
//Maybe try background worker, but how to wait until
//login is complete?
myService.Login(account,password,type);
return myService.IsLogin();
}
catch(Exception exception)
{
MessageBox.Show(exception.message);
}
return false;
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
myService.Logout(); //Logout from service
myService = null;
}
}
는 시간 내 주셔서 감사합니다.
명확하고 유용한 답변을 제공해 주셔서 감사합니다. – Dylan