低性能机器上的浏览器错误
ai制作了一个silverlight图像上传器,代码运行正常,但在低性能机器上,浏览器(Firefox,Chrome)给出这样的错误:插件“silverlight”没有响应!,调整大小方法有CPU成本和导致问题。
我现在需要这样想:
- 有一种方法可以在浏览器上设置“检查插件超时”吗?
有一种方法可以使用 OpenFileDialog 异步加载文件吗?
private void btnSelectFiles_Click(对象发送者, RoutedEventArgs e) { 文件=新列表<文件>(); OpenFileDialog dlg = new OpenFileDialog(); dlg.Multiselect = 参数.multiselect; dlg.Filter = 参数.filter; if (dlg.ShowDialog() == true) { JavaScriptHelper.Invoke("SilverUploaderDebug", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " - Abrindo arquivos"); foreach(dlg.Files 中的 var 文件) { 尝试 { var f = 新文件(); JavaScriptHelper.Invoke("SilverUploaderDebug", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " - Abrindo " + file.Name); JavaScriptHelper.Invoke("SilverUploaderDebug", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " - Redimensionando " + file.Name + "(grande)"); var Stream1 = file.OpenRead(); f.data1 = ImageHelper.Resize(stream1,Parameters.img_width,Parameters.img_height,90,f); JavaScriptHelper.Invoke("SilverUploaderDebug", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " - OK"); JavaScriptHelper.Invoke("SilverUploaderDebug", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " - Redimensionando " + file.Name + "(pequeno)"); var Stream2 = file.OpenRead(); f.data2 = ImageHelper.Resize(stream2,Parameters.img_thumb_width,Parameters.img_thumb_height,90,f); JavaScriptHelper.Invoke("SilverUploaderDebug", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " - OK"); f.name = 文件.Name; f.extension = 文件.Extension; 文件。添加(f); JavaScriptHelper.Invoke("SilverUploaderFileLoaded",JsonHelper.SerializeToJsonString(f)); } 捕获(异常前) { JavaScriptHelper.Invoke("SilverUploaderException", ex.Message); } } if (参数.auto_upload) 上传(); } }
ai make an silverlight image uploader the code is running ok, but on a low performance machines the browser(Firefox,Chrome) give an error like this: The plugin 'silverlight' is not responding!!, the resize method have a cpu cost and cause problem.
I need to now this think's:
- Have one way to set this "Check Plugin TimeOut" on a browser?
Have one way to load files with OpenFileDialog assync?
private void btnSelectFiles_Click(object sender, RoutedEventArgs e) { files = new List<File>(); OpenFileDialog dlg = new OpenFileDialog(); dlg.Multiselect = Parameters.multiselect; dlg.Filter = Parameters.filter; if (dlg.ShowDialog() == true) { JavaScriptHelper.Invoke("SilverUploaderDebug", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " - Abrindo arquivos"); foreach (var file in dlg.Files) { try { var f = new File(); JavaScriptHelper.Invoke("SilverUploaderDebug", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " - Abrindo " + file.Name); JavaScriptHelper.Invoke("SilverUploaderDebug", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " - Redimensionando " + file.Name + "(grande)"); var stream1 = file.OpenRead(); f.data1 = ImageHelper.Resize(stream1, Parameters.img_width, Parameters.img_height, 90, f); JavaScriptHelper.Invoke("SilverUploaderDebug", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " - OK"); JavaScriptHelper.Invoke("SilverUploaderDebug", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " - Redimensionando " + file.Name + "(pequeno)"); var stream2 = file.OpenRead(); f.data2 = ImageHelper.Resize(stream2, Parameters.img_thumb_width, Parameters.img_thumb_height, 90, f); JavaScriptHelper.Invoke("SilverUploaderDebug", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " - OK"); f.name = file.Name; f.extension = file.Extension; files.Add(f); JavaScriptHelper.Invoke("SilverUploaderFileLoaded",JsonHelper.SerializeToJsonString(f)); } catch(Exception ex) { JavaScriptHelper.Invoke("SilverUploaderException", ex.Message); } } if (Parameters.auto_upload) upload(); } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Silverlight 插件“没有响应”的原因是您正在 UI 线程上运行长时间运行的操作。为什么不将图像文件的实际读取 (
file.OpenRead()
) 以及对这些文件的操作移至BackgroundWorker
上呢?我不知道您的upload
方法是做什么的,希望它很好并且是异步的,但您可能想考虑这是否也花费了不小的时间。如果您想改善用户体验,您可以尝试在后台线程运行时在 UI 上添加“正在进行中”指示。
The reason the Silverlight plugin is "not responding" is that you're running long-running operations on the UI thread. Why not move the actual reading of image files (
file.OpenRead()
), and manipulation of those, onto aBackgroundWorker
? I don't know what yourupload
method does, hopefully it's nice and asynchronous, but you might want to think whether that's taking a non-trivial time too.If you want to improve the user experience you can then try adding a "work in progress" indication on the UI while your background thread chugs along.