我想通过运行线程使ActionResult生效。当线程正在运行时,我将在加载时返回View,但是当线程完成时,ActionResult返回另一个View
我的代码如下:
private static void ExecuteScrapper()
{
ScriptEngine pythonEngine = IronPython.Hosting.Python.CreateEngine();
ScriptSource pythonScript = pythonEngine.CreateScriptSourceFromFile(HostingEnvironment.MapPath("/PythonScript/main.py"));
var searchPath = pythonEngine.GetSearchPaths();
searchPath.Add(HostingEnvironment.MapPath("/PythonScript/"));
searchPath.Add(HostingEnvironment.MapPath("/PythonScript/drivers/"));
pythonEngine.SetSearchPaths(searchPath);
var result = pythonScript.Execute();
}
private ScrapperEnum.ScrapperOperations scraperParam;
private Thread t = new Thread(new ThreadStart(ExecuteScrapper));
public ActionResult RunScrapper(ScrapperEnum.ScrapperOperations operation)
{
scraperParam = operation;
t.Start();
bool run = false;
while(t.IsAlive)
{
if(!run)
{
run = true;
return View("ScrapperLoadingView");
}
}
return RedirectToAction("Scrapper");
}
我不知道该怎么做,因为在这段代码中我返回ScrapperLoginView时,它会中断,因此该函数不会切换视图。>
我想通过运行线程使ActionResult生效。当线程运行时,我将在加载时返回View,但是当线程完成后,ActionResult返回另一个View,我的代码如下:private ...
如果我没错,您只需要添加一个其他