Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
Hi to Everyone,

My Scenario:
I will get some set of datas from two stored procedure. I will store first stored procedures data into datasetA. And data of second Stored procedure will be stored in datasetB. i have an another common datasetC. On that DatasetC i am going to merge these two datasets.

After Merging the Datasets i have to show in Gridview.

Now my Problem is,
I have to run those two stored procedures at a same time using threadstart(threading).
First Stored Procedure has a time delay of 8sec, and second SP has a time delay of 3 sec,

I need to fill the grid view when the second one got finished and it has to wait for the first stored procedure, After First Sp got finished it needs to merge with second one and it have to shown in grid view.

please help me to get clear out of this.

For your Kind Reference:
First Stored Procedure
SQL
Create procedure Athread
as
begin
WAITFOR DELAY '00:00:08'
select * from area where areaname LIKE 'C%';
end


Second Stored Procedure
SQL
Create procedure Bthread
as
begin
WAITFOR DELAY '00:00:03'
select * from area where areaname LIKE 'F%';
end



I am Calling the below code in an Button Event
C#
Thread thread1 = new Thread(new ThreadStart(Athread));
            Thread thread2 = new Thread(new ThreadStart(Bthread));

            thread1.Start();
            thread2.Start();


I am Having two Functions to call these Sp and two display in Grid view
C#
dataset dsA;
dataset dsB;
dataset dsCommon;
public void Athread()
        {
            dsA = ExecSP("Athread");
            if (dsA.Tables[0].Rows.Count > 0)
            {
                dsCommon.Merge(dsA);
                gvthread.DataSource = dsCommon;
                gvthread.DataBind();            
            }
            return;
        }
        public void Bthread()
        {
            dsB = ExecSP("Bthread");
            if (dsB.Tables[0].Rows.Count > 0)
            {
                dsCommon.Merge(dsB);
                gvthread.DataSource = dsCommon;
                gvthread.DataBind();     
            }
            return;

        }


Please help me in Threading and to finish this...
Posted
Comments
thursunamy 15-May-14 10:03am    
Do you have to use Threading ? I think you can use Ajax requests.
Maria Norbert 16-May-14 0:36am    
Can you Explain this Detaily, How to manage Ajax requests?
Sunasara Imdadhusen 16-May-14 1:56am    
Can you please let us know why you are using Thread. is there any special requirement?
Maria Norbert 16-May-14 2:01am    
Special Requirement is After the completion of the second stored procedure it should fill the grid view and it needs to wait for the first stored procedure which is already running. After the First Stored procedure Got Finished, it has to append its data with the already shown data in grid view..

To make the process sleep and to wait am using thread.

If there is any alternative, it will be welcomed. Please let me know the Alternative.

Thanks in Advance.

1 solution

Hello Maria,

Without using thread you can call your method like:
C#
Page_Load(....)
{
    if(!IsPostBack)
    {
         functionA();
    }
}
public void functionA()
{
      dsA = ExecSP("Athread");
      if (dsA.Tables[0].Rows.Count > 0)
      {
           dsCommon.Merge(dsA);
           gvthread.DataSource = dsCommon;
           gvthread.DataBind();
           //From here you can call your functionB
           functionB();
      }
return;
}
public void functionB()
{
      dsB = ExecSP("Bthread");
      if (dsB.Tables[0].Rows.Count > 0)
      {
           dsCommon.Merge(dsB);
           gvthread.DataSource = dsCommon;
           gvthread.DataBind();
      }
return;
}
 
Share this answer
 
Comments
Maria Norbert 16-May-14 5:52am    
From this code, It will merge the records of functinoA and FunctinB and then only it will show to us.,

My requirement is The Grid Should be loaded when the Function A is executed and it has to show the records. after a few seconds it automatically needs to bind the data of FunctionB.

The Main thing is which one returns quickly it has to shown up in grid. It needs to wait for the Function A..
Sunasara Imdadhusen 16-May-14 6:00am    
In that case you have to use AJAX to display sub records in to the Grid. Have you know how to use AJAX using Java Script or Asp.Net
Maria Norbert 16-May-14 6:29am    
Sorry Sunasara, Can u please explain that...

My requirement is it has to display the first in data to grid and it merges the second in and so on..
Sunasara Imdadhusen 16-May-14 6:39am    
Hey Maria, is something like this your requirement http://jsfiddle.net/amorris/mz9ue/
Maria Norbert 16-May-14 7:01am    
In that grid, am asking to print only the first line after a few seconds it needs to bind second line automatically.,

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