Click here to Skip to main content
15,885,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
// insertion function return true if insertion done
public bool insertion()
   {
       bool result=false;
       try
       {
           object[,] obj = new object[,] { { "@Name", txtName.Text }, { "@Address", txtAddress.Text }, { "@EmailId", txtEmailId.Text } };
           result=DB.ExecuteNonQuery_SP("InsertThreading", obj);
       }
       catch (Exception ex) { }
       return result;
   }

//thread for insertion and display "success" if InsertionThreadMethod() is true
 protected void btnSave_Click(object sender, EventArgs e)
{

        ThreadStart InsertionThread = new ThreadStart(insertion);
        Thread t1 = new Thread(InsertionThread);
        t1.Priority = ThreadPriority.Highest;
        t1.Start();
        if (InsertionThreadMethod() == true)
        {
            lblResult.Text = "Insertion Successful";
        }


}


error showing :CS0407: 'bool Threading_Threading.insertion()' has the wrong return type
Posted
Updated 23-Jul-13 19:34pm
v2

1 solution

First off, why are you making use of a thread when you still want to wait for the thread to finish before finishing the event method? Might as well call the insertion method from the btnSave_Click method without the use of threads especially since you're still going to wait for its result.

A method which is started in a thread could not return a value. If you need such functionality, you must make use of a thread safe variable. In my opinion, from the code that you're showing, it would be best if you remove the thread completely and instead just call the insertion method.
 
Share this answer
 
Comments
Mohammed Shamsheer 24-Jul-13 1:57am    
thanks Ryan i need to display in my web page label insertion successfull if insertion done through thread
Ryan Zahra 24-Jul-13 2:03am    
If you still want to use the thread, why not just set the text of the label directly from the thread?
Mohammed Shamsheer 24-Jul-13 2:06am    
ya it display but we have to confirm that the thread executes successfully
Ryan Zahra 24-Jul-13 2:12am    
Check the answer given here: http://stackoverflow.com/questions/1001973/how-to-tell-if-a-thread-has-exited-successfully
It states exactly how and when a thread is stopped.
Mohammed Shamsheer 24-Jul-13 2:18am    
Thank u

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