简体   繁体   English

服务器等待文件在Asp.net C#中的保存完成

[英]Server Wait file save complete in Asp.net C#

I save image file into folder in Form_Load and used that image in client side. 我将图像文件保存到Form_Load文件夹中,并在客户端使用了该image sometimes does not show image . 有时不显示image but after refresh page image show. 但刷新页面后显示image I want server wait till image saved complete. 我要服务器等到image保存完成。

  System.Drawing.Image barcodeImage = b.Encode(BarcodeLib.TYPE.CODE128, lstTicket[0].Barcode.ToString(), 250, 100);
   barcodeImage.Save(Server.MapPath("~/temp/") + lstTicket[0].Barcode.ToString() + ".jpg");

and Client Side 和客户端

  <div id="Barcode" style="text-align: center; margin-top: 10px;">
      <img src="/temp/<%=item.Barcode + ".jpg"%>" style="width: 200px; height: 40px;" />
  </div>

I have the same problem and your solution is : 我有同样的问题,您的解决方案是:

You can use 您可以使用

$(window).on("load"),function(){}

instead of 代替

$(document).ready(function () {}

the alert box doesn't appear until after your barcode image are loaded and your problem will be solve 直到加载条形码图像之后,您的问题才会得到解决,才会显示警报框

I'm amazed that the server can't write this image in time, but perhaps you should change the way it's done, rather than filling up the server hard disk with images of barcodes, write a handler that you put into the HTML as the img src eg <img src="barcode generator.ashx?id=12345" ... and when the client browser calls to that handler to get the barcode, generate it as a png (not jpg, jpg should never be used for barcodes) and send it 我很惊讶服务器无法及时写入该图像,但是也许您应该更改其完成方式,而不是用条形码的图像填充服务器硬盘,而是编写一个放入HTML的处理程序作为img src例如<img src="barcode generator.ashx?id=12345" ...并且当客户端浏览器调用该处理程序以获取条形码时,请将其生成为png(而不是jpg,永远不要将jpg用于条形码)并发送

See something like this: Display Image using ashx Handler 看到类似的内容: 使用ashx处理程序显示图像

Here the guy is getting his avatar image out of db based on primary key supplies in URL - your situation is less complex - you can just generate the barcode data directly (put the barcode value you want to generate into the URL in the HTML , as a parameter 这家伙根据URL中的主键提供将头像图像从db中取出-您的情况就不那么复杂了-您可以直接生成条形码数据(将要生成的条形码值放入HTML的URL中,如一个参数

If you need more code samples etc google for something like "generate image dynamically ashx" 如果您需要更多的代码示例,例如google,例如“动态生成图像ashx”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM