得到问题以执行异步并等待并行执行方法并获得结果 [英] Getting problem to perform Async and await for Parallel execution methods and getting result

查看:75
本文介绍了得到问题以执行异步并等待并行执行方法并获得结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在索引视图中执行操作时

必须同时从数据库中读取学生数据,同时读取另一个函数中每个学生的科目,同时将科目绑定到索引视图

,我期待并行执行和结果

When I Perform an action in Index View
Students data has to be read from database at the same time read subjects for each Student in another function and at the same time binding subjects to Index View
, i am expecting parallel execution and result

public class tbl_Student
{
    public string Name {get;set;};
    public string HallTicket {get;set;}
}

public class tbl_Subjects
{
    public string HallTicket {get;set;};
    
    public string Subject1 {get;set;}
    public string Subject2 {get;set;}
}

[HttpPost]
public ActionResult Index()
{
    Go();

    return View();
}

public async static void Go()
{
    List<tbl_student> objstudents= await GetStudentData();

    foreach (var onestudent in objstudents )
    {
        List<tbl_subjects> objsubjects = GetSubjectsForHTNO (onestudent );
    }

    private static Task<list><tbl_student>>GetStudentData()
    {
        List<tbl_student> objStudetns=...
        // Here i am fetching Data
        return objStudents
    }
    public static List<tbl_subjects> GetSubjectsForHTNO(tbl_Student objStudent)
    {
        List<tbl_subjects> objsubjects= ...
        
        return objsubjects
    }

    // here i need to bind objsubjects to Index View only
    // How Shoud I
}



谢谢


Thank you

推荐答案

您在代码中缺少一个小括号。



有关详细信息,请参阅http://www.dotnetperls.com/async。



这个异步,等待我使用3.5的东西看起来像代码糖果,我看不出它上面提供了什么使用线程并读取运行状态。 />


也许它有一些用于交叉线程的东西或更好的中止线程(我们现在从不这样做)



我自己可以在这里上课,因为我被告知我们应该使用流程来进行长期运行而且m eans编写dll来进行处理,然后不得不将结果与程序的客户端挂钩。



生成一个进程很慢,因为编组结果,但至少你可以杀死它不像线程卡住和等待套接字回复。



会很高兴



You is missing a close bracket in the code.

See http://www.dotnetperls.com/async for more info.

This Async, Await stuff to me who uses 3.5 seems like code candy and i cannot see what it offer me above using a thread and reading the running state.

maybe it has something in it for cross threading or something better to abort threads (We never do that do we now)

I could do with a lesson here myself because i am told we should be using processes for long running operations and that means writing dll's to do the procesing and then having to hook the results back up with the client side of the program.

Giving birth to a process is slow as is marshaling the results but at least you can kill it dead unlike threads that are stuck and waiting on a socket to reply.

would be nice to do

Process P=Process.OnTheFly("{OpenFile();Read();Return 123;}");
P.Start();
Thread.sleep(5000);
if (P.State=="Running")
  P.Kill();
else
  {
   int Num=P.Value
   P.Close();
  }


这篇关于得到问题以执行异步并等待并行执行方法并获得结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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