Hi all,
I have problem when dynamic loading image from SQL Server and display to picture box. Images be continuously saved to SQL .
If i using only one client session, there no problem. But when I open 2 or more client sessions and trying command to loading image (only one image about 300KB), it be hang and make to remain sessions can’t loading image. Until I closing 2nd client which make hang, then remain sessions automatic re-load image again by last command. If I doing new manual command to loading image, even client 1, it will be hang again!
I had trying:
Note:
Any one have solution to solver this problem, please help me!
Thanks!
Looks like your code is locking when using SQL Server. Send a small test case without using SQL server showing the issue please. I tried with a file, with a theme image, with a URL and it always works well.
Dear Luca,
I create a simple project:
I’m testing:
Thanks!
System.Drawing.Image.FromFile locks the file and keeps it locked. It’s not a Wisej issue, it’s the way System.Drawing works.
There are several ways to load an image from a file e release the lock:
https://stackoverflow.com/questions/6576341/open-image-from-file-then-release-lock
Additionally with Wisej you don’t need to use Image.FromFile since you can assign the file to ImageSource.
If you use Image.FromStream you will get the same problem since the stream is kept open. That’s the way it works. You have to load the image and release the file or the stream.
Dear Luca,
You just sent me good information!
I understand of your attention.
I’ve creating the test case as below:
stream = New FileStream(“c:\DM_DC_MB.jpg”, FileMode.Open, FileAccess.Read)
PictureBox1.Image = Image.FromStream(stream)
stream = New FileStream(“c:\DM_DC_MB.jpg”, FileMode.Open, FileAccess.Read)
PictureBox1.Image = Image.FromStream(stream)
stream.Close() // or stream.Dispose
stream = New FileStream(“c:\DM_DC_MB.jpg”, FileMode.Open, FileAccess.Read)
PictureBox1.Image = Image.FromStream(stream)
In another button, I’m using: stream.Close(). After that I can change DM_DC_MB.jpg filename => successful to unlock file.
I have one question that how to use PictureBox1.ImageSource with local file? I have testing some local path file but it can’t load image.
Thank you so much!
The correct way to use Image.FromFile or FromStream with System.Drawing is like this:
using (var image = Image.FromFile(file)) { return new Bitmap(image); }
The using keyword will dispose the image when the block is exited. It’s similar to try/finally.
The new Bitmap() line causes the full reading/decoding of the file or the stream.
If you want to use the file directly simply assign it to pictureBox1.ImageSource.
If you still have problems using the images please attach a test case showing the issue and the code you are using.
Dear Luca,
I have just find that if I using IIS express to debug then everything fine.
But when I publishing to IIS server that have problem that have only 2 client session can be working, even my web site is nothing (no load any picture). If I open more tabs, example 10 tabs, then the tab from 3 to 10 to be hang. Until I close tab 2nd then all tabs which be hang will auto loading again!
I have trying to push other web site (not build by Wisej) to IIS server on my laptop, that working fine with more clients (IIS server version 10.0.17763.1 on Windows 10 64bits home edition)
May be have problem about connection between IIS server and web server was. Do you have any experience about publishing to IIS?
Thanks!
You need to attach a test case or I won’t be able to tell you what’s wrong in the code. I cannot reproduce the issue you describe (IIS or IIS Express) since it’s related to the wrong usage of Image.FromFile or FromStream.
Dear Luca,
I have just fix my problem by using Wisej.HostService.exe in other discuss of your. Wisej.HostService.exe really is good solution for publishing my web site without using IIS server.
The problem may be is combine between IIS and Wisej web site built.
After using Wisej.HostService.exe, I don’t have problem related to “from file” or “stream”!
Thank you so much for supporting!
Please login first to submit.