ASP中的异步多线程> NET C# [英] Async Multi Threading in ASP>NET C#

查看:79
本文介绍了ASP中的异步多线程> NET C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个庞大的数据要运行,这需要花费大量的时间,所以我认为Threading可能会很快为我做好工作。



我做什么:从ASP.NET前端调用SQL存储过程并在那里进行处理。



我需要什么:我已经拆分将数据分成不同的批次并为每个批次创建相应的SP。现在我只需按一下按钮就可以同时运行所有SP。



请帮助!



我使用下面的代码,但似乎没有并行运行:(



  protected   void  Button3_Click( object  sender,EventArgs e)
{
Thread t1 = new Thread(Method1);
Thread t2 = new Thread(Method2 );

t1.Start();
t2.Start();

t1.Join();
t2.Join();

}
void Method1()
{
for int i = 0 ; i < 10000 ; i ++)
{
R esponse.Write( hello1 + i);
Response.Write( < br>);
}
}

void Method2()
{
for int i = 0 ; i < 10000 ; i ++)
{
Response.Write( 恩斯特 + i);

}
}

解决方案

hi,



你可以使用

[这个]



你可以使用多线程,如果你不使用相同的资源



祝你好运



jeremy


你说并行..你想得到这样的输出吗?

Hello1

恩斯特



Hello2

恩斯特.....



使用线程Method1和Method2可以同时开始执行,但不能一起结束。



也许你应该更清楚地表达你的问题。


< blockquote> 处理长时间运行的任务机智h异步处理程序和XMLHTTP [ ^ ]


I have a huge data to run which takes awful amount of time so thought Threading might do the job for me quickly.

What i do : Call SQL Stored Procedures from ASP.NET front end and processing takes place there.

What i need : I have split the data into different batches and created respective SP's for each. Now i require all SP's to be running at the same time at a single button click.

Please help !

I used the below code but it doesnt seem to run parallely :(

protected void Button3_Click(object sender, EventArgs e)
   {
       Thread t1 = new Thread(Method1);
       Thread t2 = new Thread(Method2);

       t1.Start();
       t2.Start();

       t1.Join();
       t2.Join();

   }
  void Method1()
   {
       for (int i = 0; i < 10000; i++)
       {
           Response.Write("hello1"+i);
           Response.Write("<br>");
       }
   }

  void Method2()
  {
      for (int i = 0; i < 10000; i++)
      {
          Response.Write("Ernst" + i);

      }
  }

解决方案

hi,

you can use
[This]

you can use multi thread if you don't use the same resource

good luck

jeremy


you say parallely..do you want to get output like this?
Hello1
Ernst

Hello2
Ernst.....

use thread Method1 and Method2 can begin excute at the same time,but not end together.

maybe you should express you quesion more clearly.


Processing Long Running Tasks With Asynchronous Handlers and XMLHTTP[^]


这篇关于ASP中的异步多线程&gt; NET C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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