在我完成这项任务之后,我准备向使用非洲复兴开发银行的客户提供最新情况时,我有了一个缓慢的任务。 在我的客户中,我多次呼吁更新成果网。 为了了解情况,其联系人通过联系清单证明他们是否活着。
I have implemented the service as WCF. I generate async methods when I add the service reference to my web client.
The code works fine, however the screen locks momentarily when the callbacks fire - I think this is because they all happen one after the other and all of them repaint the GridView within quick succession. I don t want this glitch to happen -I was hoping the AJAX implementation would be able to partially update the GridView as results come back from the service via the callbacks.
The only way I can make this look nice is to launch the async calls in a separate client thread and then use a timer to repaint the data to the grid (the same data that s being updated in the separate thread via the callbacks).
我将这一微型项目作为学习练习,然后我与MVC3一样了解差异。
• 《Snippet法典》(没有单独校对,导致在警示期间减慢的屏幕):
//get list of connections from session
ConnectionList myConns = Session[SESSION_ID] as ConnectionList;
//pass into async service call
GetAllStatusAsync(myConns);
protected void GetAllStatusAsync(ConnectionList myConns)
{
Service1Client myClient = new WcfConnectionServiceRef.Service1Client();
myClient.AsyncWorkCompleted += new EventHandler<AsyncWorkCompletedEventArgs>(myClient_AsyncWorkCompleted);
foreach (ConnectionDetail conn in myConns.ConnectionDetail)
{
//this call isnt blocking, conn wont be updated until later in the callback
myClient.AsyncWorkAsync(conn);
}
}
//callback method from async task
void myClient_AsyncWorkCompleted(object sender, AsyncWorkCompletedEventArgs e)
{
ConnectionDetail connResult = e.Result;
//get list of connections from session
ConnectionList myConns = Session[SESSION_ID] as ConnectionList;
//update our local store
UpdateConnectionStore(connResult, myConns);
//rebind grid
BindConnectionDetailsToGrid(myConns);
}
问题在于——能否以更好的方式来做到这一点? (为了避免造成问题,随着结果的产生,使电网得到部分更新)我实际上不想使用单独的客户线,如以下幻灯:
// Perform processing of files async in another thread so rendering is not slowed down
// this is a fire and forget approach so i will never get results back unless i poll for them in timer from the main thread
ThreadPool.QueueUserWorkItem(delegate
{
//get list of connections from session
ConnectionList myConns = Session[SESSION_ID] as ConnectionList;
//pass into async service call
GetAllStatusAsync(myConns);
});
最新资料:
根据要求添加标记:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ASForm.aspx.cs" Inherits="Web_Asp_FBMonitor.ASForm" Async="true" EnableSessionState="True" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>
ASP.NET Connection Test (Client in ASYNC, Server in ASYNC)
</h2>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<p>
<%--This update panel shows the time, updated every second--%>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<h3> <asp:Label ID="LabelTime" runat="server" Text=""></asp:Label> </h3>
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick"> </asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</p>
<p>
<%--This update panel shows our results grid--%>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default.aspx">Client Sync Page</asp:HyperLink>
<br />
<asp:Button ID="ButtonUpdate" runat="server" Text="Update"
onclick="ButtonUpdate_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</p>
</asp:Content>
<><>>>
我期待着一个简明的客户方联合倡议的例子。 收到的选择是好的,非常受赞赏,但委托方共同提交书面材料是我自己不per的,将为此给予回报。