에 기다리는 동안 ASP를 텍스트 상자에 메시지를 표시하는 방법 :나는 두 WCF 서비스 호출이 긴 WCF 서비스 호출
[OperationContract]
void ClosePeriod();
[OperationContract]
string GetLogs();
ClosePeriod 방법은 1 시간 걸리는 저장 프로 시저를 실행하고 로그 메시지를 생성합니다. GetLogs 메서드는 ClosePeriod 메서드에서 생성 된 로그 메시지를 반환합니다.
ClosePeriod 서비스 호출을 기다리는 동안 ASP.Net 웹 페이지에 로그 메시지를 표시하려고합니다.
<asp:UpdatePanel ID="UpdatePanelClosing" runat="server">
<ContentTemplate>
<asp:Timer ID ="TimerLog" runat ="server" Interval ="3000" OnTick="TimerLog_Tick" Enabled="true"></asp:Timer>
<table>
<tr>
<td>
<div style="margin-top: 10px; margin-bottom: 70px">
<asp:Button runat="server" ID="BtnExecuteClosing" Text="Execute" Width="105px" Height="35px" OnClick="BtnExecuteClosing_Click" />
</div>
</td>
</tr>
<tr>
<td>
<p>Process Log:</p>
</td>
</tr>
<tr>
<td colspan="3">
<asp:TextBox ID="TxtProcessLog" runat="server" Width="930px" Height="270" TextMode="MultiLine" Style="resize: none;"
ReadOnly="true" Text="">
</asp:TextBox>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
지금까지 ClosePeriod 메서드를 비동기 적으로 호출하려고 시도했지만 타이머를 사용하여 TxtProcessLog 텍스트 상자를 업데이트하려고했습니다.
protected async void BtnExecuteClosing_Click(object sender, EventArgs e)
{
await webservice.ClosePeriodAsync();
}
protected void TimerLog_Tick(object sender, EventArgs e)
{
string log = webservice.GetLogs();
TxtProcessLog.Text = log ;
}
그러나 TxtProcessLog 텍스트 상자는 ClosePeriod 서비스 호출이 완료된 후 업데이트됩니다. 내가 잘못하고 있니? 다른 방법을 제안하십시오.
테스트 목적으로 System.Threading.Thread.Sleep (10000)을 추가했습니다. in ClosePeriod. GetLogs()는 빈 문자열을 반환하지 않습니다. – devphil
updatepanel에서 타이머를 사용하지 마십시오. http://encosia.com/aspnet-ajax-timer-trouble-location-is-key/ 해결 방법은 updatepanel 내의 버튼을 트리거하는 clientside 스크립트를 작성하는 것입니다. 특정 간격 (setTimeout (func, 3000);)으로, 서버 측에서 getlogs 메소드를 호출합니다. css-> display : none을 통해 버튼이 보이지 않게하십시오. 좋은 방법은 아니지만 작동해야합니다. WCF 서비스 메소드 또는 페이지 메소드 "getlogs"를 호출하고 jQuery를 통해 호출하는 것이 가장 이상적입니다. –