-
April 26th, 2014, 04:07 PM
#1
[RESOLVED] Hide waitcursor when saving image to file
I have a form that has to be run hidden only - there is a save operation that is done for every n seconds and the user cannot see any flicker or wait cursor during this time.
For every n secs, it captures the current window as image and saves it to disk via a Bitmap CopyFromScreen() logic. However, a waitcursor appears everytime the save is done to the disk which can be upto 5 times an hour.
so, bmp.save(filename,Imageformat.jpeg) produces a waitcursor. I understand it happens due to the I\O op done here. But I dont want the user to see a process going on in the background - the form where this happens is hidden and is not visible in the taskbar at all, yet the waitcursor appears - coz its a system disk operation.
How to prevent the waitcursor not being shown or is there any way the image can be saved without the user interrupted by the waitcursor every now and then?
Any help appreciated. Thanks.
-
April 26th, 2014, 05:45 PM
#2
Re: Hide waitcursor when saving image to file
Pass the bitmap from the CopyFromScreen() method into a second thread and save it there. Check out QueueUserWorkItem().
-
April 26th, 2014, 06:12 PM
#3
Re: Hide waitcursor when saving image to file
Originally Posted by Arjay
Copy the bitmap over to a second thread and save it there.
was just about to try that - but the waitcursor appears across the system, not just in the application screen - when you hover over it. I believe the user would see it regardless of it in another thread - let me try and get back to you anyway.
-
April 26th, 2014, 07:07 PM
#4
Re: Hide waitcursor when saving image to file
Originally Posted by CM2013
was just about to try that - but the waitcursor appears across the system, not just in the application screen - when you hover over it. I believe the user would see it regardless of it in another thread - let me try and get back to you anyway.
It appears in the app because you are hanging the UI thread while copying. I doubt a waitcursor will show up when the save is in another thread.
-
April 26th, 2014, 09:49 PM
#5
Re: Hide waitcursor when saving image to file
It did not work - coz its not that the wait cursor appears on the UI screen - its across the system. The system's cursor turns briefly to a waitcursor and then comes back to default due to the I\O op. This happens in a new thread as well using a parametrized Threadstart and passing the function name that has the bmp to the thread.
-
April 26th, 2014, 10:14 PM
#6
Re: Hide waitcursor when saving image to file
Originally Posted by CM2013
It did not work - coz its not that the wait cursor appears on the UI screen - its across the system. The system's cursor turns briefly to a waitcursor and then comes back to default due to the I\O op. This happens in a new thread as well using a parametrized Threadstart and passing the function name that has the bmp to the thread.
I'm not seeing that behavior when I create a Bitmap and call its .Save method. I/O generally doesn't cause this behavior (because if it did, you'd see a wait cursor when you copied large files). Perhaps the wait cursor you are seeing isn't because of the Save but from something else? Try saving in a test program (like I did) and you won't see the wait cursor.
-
April 26th, 2014, 10:39 PM
#7
Re: Hide waitcursor when saving image to file
you were right - the i\o copy didnt make the waitcursor - I had this lets say, Save2() functionin a timer tick. Even for a 10 sec tick, it shows the wait cursor. Do you know why or how it can be avoided pls?
-
April 26th, 2014, 10:39 PM
#8
Re: Hide waitcursor when saving image to file
maybe I'll put the timer in another thread then?
-
April 26th, 2014, 11:07 PM
#9
Re: Hide waitcursor when saving image to file
even timer in a new thread didnt help - I'll try BackgroundWorker thread.
-
April 28th, 2014, 06:11 PM
#10
Re: Hide waitcursor when saving image to file
a backgroundworker thread to do a non-async op does not work either. Timer is useless if its going to show waitcursor every few minutes even though the I\O op doesn't require that.
-
April 28th, 2014, 09:01 PM
#11
Re: Hide waitcursor when saving image to file
Have you isolated whether its' the save operation (which I don't think it is)?
More likely it's the CopyFromScreen operation. Can you comment out the Save and see if the waitcursor still appears?
Can you try another approach to grab the screen contents rather than CopyFromScreen()?
-
April 28th, 2014, 09:24 PM
#12
Re: Hide waitcursor when saving image to file
yes, the save() is isolated. Commenting that out does not show the waitcursor. So, assigning a bitmap from CopyFromScreen() to a picturebox control does not cause any waitcursor, but saving the picturebox1.Image.Save() does cause the waitcursor to show.
-
April 28th, 2014, 09:34 PM
#13
Re: Hide waitcursor when saving image to file
Rather than calling .Image.Save(), extract the stream out of .Image, send it to a second thread, then recreate it into a new Image and call save from there. I think the Image being tied to the picturebox is throwing the wait cursor.
-
April 28th, 2014, 10:13 PM
#14
Re: Hide waitcursor when saving image to file
saving the bmp to memory stream like bmp.save(memst) and then passing the memst object to another thread wherein the memst is copied to a FileStream object produces the same result - it flickers showing a waitcursor.
Maybe its closer related to the OS and my hardware config as it does not happen in your system?
am running a decent config - win 7, 1 GB RAM and 1.73 Ghz CPU.
-
April 28th, 2014, 10:21 PM
#15
Re: Hide waitcursor when saving image to file
a FILESTREAM WRITE COPYING THE MEMORY STREAM TO A BUFFER produces the same result.
Sorry about the caps.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|