必须执行两项任务 [英] Two tasks has to run parrallaey

查看:104
本文介绍了必须执行两项任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个Web服务是在一个表中插入行数,而一个biztalk应用程序可以显示来自同一表和进程的行.
这里这两个任务是按比例执行的.但是根据我的代码,当一个任务执行下一个任务时,它不会像这样执行,直到下一个任务完成为止.如何实现两个任务paralley

One webservice is insert number of rows in one table and one biztalk application can pic that rows from same table and process.
here these two tasks are did paralally .but according my code its not doing like this when one task doing job the next one will be wait until its complete of the first one .how can i acheive two tasks paralley

推荐答案



您可以在webservice中使用线程在一种webmethod中插入数据,这将使该方法在后台运行进程.
并使用另一种方法可以获取数据
Hi,

You can use threading in webservice to insert data in one webmethod , which will make that method to run process in background.
And using another method you can get data
Two webmethods are as below...
       [WebMethod]
       public void InsertData()
       {
           Thread myThread = new Thread(StartThread1);
           myThread.Start();
       }


[WebMethod]
       public DataSet Getdata()
       {
           SqlConnection myconn = new SqlConnection();
           myconn.ConnectionString = "Data Source=Demo-PC\\SQLEXP1;Initial Catalog=DB1;User ID=sa;Password=******";
           string strsql = "select * from Table2";
           SqlCommand cmd = new SqlCommand(strsql, myconn);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataSet ds = new DataSet();
           da.Fill(ds);
           return ds;
       }
public void StartThread1()
       {
           SqlConnection myconn = new SqlConnection();
           myconn.ConnectionString = "Data Source=Demo-PC\\SQLEXP1;Initial Catalog=DB1;User ID=sa;Password=*******";
           myconn.Open();
           string strsql = "insert into Table2 values(2,'test1')";
           SqlCommand cmd = new SqlCommand(strsql, myconn);
           cmd.ExecuteNonQuery();
           strsql = "insert into Table2 values(2,'test1')";
           cmd = new SqlCommand(strsql, myconn);
           cmd.ExecuteNonQuery();
           strsql = "insert into Table2 values(2,'test1')";
           cmd = new SqlCommand(strsql, myconn);
           cmd.ExecuteNonQuery();

       }


 Call webmethods as from your page ...... 
 Data objdata = new Data();
            InsertData();
            Thread.Sleep(2000);
            DataSet ds = new DataSet();
            ds = objdata.Getdata();


        public void InsertData()
        {
            Data objdata = new Data();
            objdata.InsertData();
           

        }


----------------------------
Hope this can help you 
let me know if have any question or need more help


这篇关于必须执行两项任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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