Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi i have 3 method i want to load data like First come First Display.means which method execute first that should display in UI part .it should not wait for all method to be Complete. Here is My Sample code. this code is waiting for all function to be complete than page is loading.please help me ???



Thanks in Advance.

What I have tried:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WW1.aspx.cs" Inherits="Test.WW1" Async="true" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <h1>Welcome to Test</h1>
        <asp:Label runat="server" ID="lbl1"></asp:Label><br />
        <asp:Label runat="server" ID="Label2"></asp:Label><br />
        <asp:Label runat="server" ID="Label3"></asp:Label>
        
    </div>


</asp:Content>


protected void Page_Load(object sender, EventArgs e)
{
RegisterAsyncTask(new PageAsyncTask(LoadData));
//await LoadData();


}
private async Task LoadData()
{

var loc = getLocation();
var comp = getComapanyanme();
var dept = getDept();
await Task.WhenAll(loc, comp, dept);
lbl1.Text = loc.Result.ToString();
Label2.Text = comp.Result.ToString();
Label3.Text = dept.Result.ToString();
}

private async Task<string> getLocation()
{
await Task.Delay(2000);
string loc = string.Empty;
await Task.Run(() =>
{
//loop for delaying
for (int i = 0; i < 10000; i++)
{
for (int j = 0; j < 5000; j++)
{
loc = "Address is XYZ";
}
}

});
return loc;


}
private async Task<string> getComapanyanme()
{
//await Task.Delay(3000);
string loc = string.Empty;
await Task.Run(() =>
{
for (int i = 0; i <= 5000; i++)
{
for (int j = 0; j < 4999; j++)
{
loc = "ABC";
}
}
});
return loc;


}
private async Task<string> getDept()
{
string loc = string.Empty;
await Task.Run(() =>
{
for (int i = 0; i <= 50; i++)
{
for (int j = 0; j < 100; j++)
{
loc = "XYZ";
}
}
});
return loc;


}
Posted
Updated 8-Dec-17 1:06am
v2
Comments
F-ES Sitecore 8-Dec-17 7:10am    
You need to wait until all server-side code has finishing running before the page can be displayed. If you want the user to get the page quickly and the data to load after you'll need to re-architect the code to use ajax to load the data.
Member 13363439 14-Dec-17 6:44am    
Thanks for your replay
Member 13363439 14-Dec-17 6:47am    
Hi,
i know the ajax asynchronous but my case if i ll ajax need to re-develop lot of pages. so is there any other way in C# which ll work for my case????
F-ES Sitecore 14-Dec-17 7:04am    
It might be possible to use an UpdatePanel to make your server-side components update via ajax without having to change the code much. It's still going to involve re-working pages but will probably require much less effort that converting them to use jQuery or some such. This is why it is important to start your project using the appropriate technology from the off. Consider it a learning experience :)
Laxmidhar tatwa technologies 13-Dec-17 5:32am    
hi friend
Actualy in case of asp.net fist execute serversite code .After that generate the html and
execute.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900