winform에 익숙하지 않아 BackgroundWorker를 사용하는 방법을 알 수 없습니다.Winform에서 BackgroundWorker를 사용하는 방법 C#
는 기본적으로 난 할 노력하고있어 이것이다 : "가져 오기"및 "종료"
내가 2 개 버튼 1 개 형태가있다. ImporButton_Click을 호출하면 HttpListener가 만들어지고 주어진 URL을 수신합니다. ExitButton_Click은 양식을 닫습니다.
문제는 "가져 오기"를 누르면 양식이 멈추고 다른 누군가가 청취자에게 전화를 걸어 무료 상태가 될 때까지 "응답하지 않음"상태가됩니다.
나는 BackgroundWorker가 어떻게 그 "고착 된"문제를 극복하는 데 도움이 될 수 있는지를 입증하려고합니다. 그래서
//Program.cs
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new ConfigurationForm());
}
}
//ConfigurationForm.cs
public partial class ConfigurationForm : Form
{
public ConfigurationForm()
{
InitializeComponent();
UrlTextBox.Text = @"enter URL here";
}
private void ImporButton_Click(object sender, EventArgs e)
{
try
{
String urlToListen = UrlTextBox.Text;
//Invoke MyListener
MyListener.StartListen(urlToListen); //assume this is implemented
}
catch (Exception exception)
{
string errorMsg = String.Format("An exception occured = {0}", exception);
MessageBox.Show(errorMsg);
}
}
private void ExitButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
}
}
, 무엇을 지금 : 나는 backgroundWorker1_DoWork 방법 여기
내 코드는 지금까지입니다 호출하는 방법을 이해하지? 어떻게 backgroundWorker1_DoWork를 호출합니까 ??? 당신의 DoWorkEventArgs
를 통해 핸들러 DoWork
에 일부 argument
을 통과 RunWorkerAsync
의 두 번째 오버로드를 시도하려는 경우, 당신은이 방법을 RunWorkerAsync
backgroundWorker1.RunWorkerAsync();
를 호출 할 필요가
실제 문제가있는 곳의 코드는 표시되지 않습니다. 구현 된 "* :) 예를 들어, [this] (http://stackoverflow.com/questions/10017564/url-mapping-with-c-sharp-httplistener) 또는 [this] (http://stackoverflow.com/ 질문/13385633/serving-large-files-with-c-sharp-httplistener) –
글쎄요, 이것이 정확하게 요지입니다. backgroundWorker1을 어디에서 호출해야할지 모르겠다. – Dardar
자습서가 필요합니다. 이미 웹상에 많은 사람들이 있지만 [MSDN] (http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker%28v=vs.95%29.aspx)을 사용해보십시오. –