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;
}