다음과 같은 클래스의 골격을 가지고 있습니다. TODO : comment에서 볼 수 있듯이 여기서 AsyncEnumerator 구조를 구현할 것입니다. 이 메소드는 요청을 가져 와서 데이터를 다른 메소드로 전달하여 처리합니다. 프로세스를 기반으로 SendMilestoneReached 또는 SendFailed 이벤트를 호출하고 싶습니다. AsyncEnumerator로 인해 이러한 스레드가 다른 스레드에서 발생할 수 있습니다.비동기 적으로 발생하면 이벤트가 작동합니까?
Webtext 클래스가 호출 될 UI 스레드에 영향을 줍니까?
/// <summary>
/// Sends Webtexts.
/// </summary>
public class Webtext
{
#region Event Definitions
// Events.
public event EventHandler<SendingEventArgs> SendStarted = delegate { };
public event EventHandler<SendingEventArgs> SendFailed = delegate { };
public event EventHandler<SendingEventArgs> SendSuccessful = delegate { };
public event EventHandler<SendingEventArgs> SendMilestoneReached = delegate { };
// Shared EventArgs Object, Consumed by the Events.
SendingEventArgs EventArgs = new SendingEventArgs();
#endregion
/// <summary>
/// Executes the send request.
/// </summary>
/// <param name="Operator">The operator whos service to use.</param>
/// <param name="Username">The username of the requested operator.</param>
/// <param name="Password">The password of the requested operator.</param>
/// <param name="Content">The content to send.</param>
/// <param name="Recipient">The recipient to recieve the content.</param>
public void ExecuteSendRequest(string Operator,
string Username,
string Password,
string Content,
string Recipient)
{
//TODO: Implement Async requests here.
}
#region Event Handlers
/// <summary>
/// Called when [sending started].
/// </summary>
protected void OnSendingStarted()
{
SendStarted(this, EventArgs);
}
/// <summary>
/// Called when [send fail].
/// </summary>
protected void OnSendFail()
{
SendFailed(this, EventArgs);
}
/// <summary>
/// Called when [send successful].
/// </summary>
protected void OnSendSuccessful()
{
SendSuccessful(this, EventArgs);
}
/// <summary>
/// Called when [send milestone reached].
/// </summary>
protected void OnSendMilestoneReached()
{
SendMilestoneReached(this, EventArgs);
}
#endregion
}
구현이 포함되어 있지는 않지만 두 번째 시나리오는 적용 가능하다고 생각합니다. 본질적으로 나는 웹 요청 객체를 사용하여 비동기 적으로 호출 할 것이다. 제 3 자 라이브러리에 의해 처리되어 순차적으로 호출을 작성할 수 있지만 여전히 다른 스레드에서 호출됩니다.invoke를 사용하여 이벤트를 UI 스레드로 다시 보내는 방법에 대한 링크가 있습니까? – deanvmc
당신은 "Invoke UI Thread C#"에 의해 그것을위한 구글 수 있습니다. 이것은 매우 간단하고 간단합니다 : http://blogs.msdn.com/b/csharpfaq/archive/2004/03/17/91685.aspx – Aliostad
나는 이것을 생각하고 있었다 : http://stackoverflow.com/questions/1698889/raise-events-in-net-on-the-main-ui-thread가 좀 더 동적 인 것처럼 보입니다. – deanvmc