CS0407:'bool Threading_Threading.insertion()'的返回类型错误 [英] CS0407: 'bool Threading_Threading.insertion()' has the wrong return type

查看:361
本文介绍了CS0407:'bool Threading_Threading.insertion()'的返回类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


}





错误显示:CS0407:'bool Threading_Threading。 insert()'有错误的返回类型



error showing :CS0407: 'bool Threading_Threading.insertion()' has the wrong return type

推荐答案

首先,当你还想在完成之前等待线程完成时,为什么要使用线程?事件方法?也可以在不使用线程的情况下从btnSave_Click方法调用插入方法,特别是因为你仍然要等待它的结果。



一个方法启动在一个线程中无法返回值。如果需要此类功能,则必须使用线程安全变量。在我看来,从您显示的代码中,最好是完全删除线程,而只是调用插入方法。
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.


这篇关于CS0407:'bool Threading_Threading.insertion()'的返回类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆