【发布时间】:2018-06-30 02:33:53
【问题描述】:
这是我的代码。
protected void Send(object sender, ImageClickEventArgs e)
{
try
{
ObjCancellationTokenSource = new CancellationTokenSource();
CancellationToken token = ObjCancellationTokenSource.Token;
var ObjTask = Task<string>.Factory.StartNew(() =>
{
while (!token.IsCancellationRequested)
{
for(i=0;i<n;i++)
{
----------some operation------
}
Response.Write("<script>alert('Completed.');</script>"); // not firing
Response.Redirect("Home.aspx", false);// raising error or not firing
}
}, token);
catch (Exception ex)
{
}
}
所以,我的问题是……
一旦在任务中完成循环,我将尝试通过 Response.Write 显示警报,并且在我需要通过 Response.Redirect 将我的页面重定向到另一个页面之后...
但两者都不起作用......
我怎样才能实现它??
如果我在不使用任务操作的情况下同时执行 Response.Redirect 和 Response.Write.. 它工作正常。
我用谷歌搜索了这个 .. 但在所有站点中,都使用 Console.Write 方法来显示一些警报。我不想要那个.. 我需要显示真正的 javascript 警报并重定向页面....
请不要提供任何网络参考..提供一些代码...
谢谢大家。
【问题讨论】:
-
为什么循环中有Response.Redirect?你想重定向多少次?
-
@Hooman .. 上面不是实际代码.. 我的问题在这里.. 是否可以在任务循环中使用 responce.redirect 和 responce.write .. 我需要将控件重定向到另一个任务或内部循环完成后的页面..
-
@Hooman .. 给定的链接很有用.. 但是我使用 .net 4.0 开发的 Web 应用程序 .. “RedirectToAction”在 4.0 中不起作用...还有其他方式吗??
标签: c# asp.net cancellationtokensource