hnc*_*ncl 5 ajax asp.net-mvc async-await
在我的MVC项目中,我生成一个图像数组并将数组存储为会话变量,我使用滑动条为图像设置动画,并通过计算第一个单击和x位置之间的距离来检测鼠标移动,同时鼠标按下在画布上移动.
在我使用的控制器中:
public ActionResult Animate(int slice = 0, int udm = 0)
{
FileContentResult data;
Image objImage = null;
Bitmap im = null;
try
{
im = MySession.Current.imageArray[slice];
....
MySession.Current.image = im;
}
else
{
return RedirectToAction("Index",new {.... });
}
}
catch { }
return null;
}
Run Code Online (Sandbox Code Playgroud)
和
public ActionResult ImageOut(int udm = 0)
{
FileContentResult data;
Image objImage = null;
Bitmap im = null;
im = MySession.Current.image;
...
objImage = im.Bitmap(outputSize, PixelFormat.Format24bppRgb, m);
MemoryStream ms1 = new MemoryStream();
using (var memStream = new MemoryStream())
{
objImage.Save(memStream, ImageFormat.Png);
data = this.File(memStream.GetBuffer(), "image/png");
}
objImage.Dispose();
return data;
}
Run Code Online (Sandbox Code Playgroud)
从视图我使用Ajax:
$.ajax({
url: '/Home/Animate',
type: 'POST',
async: false,
data: {
slice: ((lastX - firstX) + nSlice),
udm: ++udm
},
success: function(data) {
if (data.udm) {
nSlice = (data.slice);
image.src = '/Home/ImageOut?' + $.param({
udm: data.udm
});
}
},
error: function() {
}
});
Run Code Online (Sandbox Code Playgroud)
我有两个问题,首先需要时间来更新视图并跳过许多图像,第二个是打开许多线程,如果访问同一页面的用户数量减慢了.我想过使用异步,但我仍在使用c#4,这可能需要对我的代码进行大量更改.我正在阅读有关SignalR的信息,我的问题是可以做到这一点(假设我只是更新用户屏幕而不是所有用户)或者是否有更好的解决方案.
我想要实现的事件顺序是:
我看到的挑战是第一个图像保持生成图像而不等待,所以我的问题是我如何使第一个动作等待,以及如何向其发送消息以生成以下图像.
我刚刚安装了VS2012 c#5,有什么例子可以帮助我!非常感谢您的建议,在此先感谢.
| 归档时间: |
|
| 查看次数: |
1015 次 |
| 最近记录: |