473,320 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

File in use by another process

Hello, Im am currently fresh out of ideas on this problem and I am aware that other people have encountered it but I still have absolutely no idea how to get around it. Basically my code does this. Takes an image, converts to tiff, and sends to MODI for OCR. However, I am using the same file for saving the images and when I try and delete the file after using it... it says "File in use..." or if I just try to save over it I get "Generic GDI+ error" below is my code for the function. Can someone pleeeeeaaasssseee show me a way to get around this. I've pretty much cant go any further with my code unless I get this done.

Expand|Select|Wrap|Line Numbers
  1. string OCRProcess(int StartX, int StartY, int EndX, int EndY, string file)
  2.         {           
  3.             Bitmap CutImage = new Bitmap(EndX - StartX, EndY - StartY);            
  4.  
  5.  
  6.             for (int x = StartX; x < EndX; x++)
  7.             {
  8.                 for (int i = StartY; i < EndY; i++)
  9.                     CutImage.SetPixel(x - StartX, i - StartY, bmpScreenshot.GetPixel(x, i));
  10.             }
  11.  
  12.             Bitmap rgbBitmap = Converter.ConvertToRGB(CutImage);
  13.  
  14.             Bitmap bitonalBitmap = Converter.ConvertToBitonal(rgbBitmap);
  15.  
  16.             ImageCodecInfo imageCodecInfo = GetEncoderInfo("image/tiff");
  17.             System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.Compression;
  18.             EncoderParameters encoderParameters = new EncoderParameters(1);
  19.  
  20.             EncoderParameter encoderParameter = new EncoderParameter(encoder, (long)EncoderValue.CompressionCCITT4);
  21.             encoderParameters.Param[0] = encoderParameter;
  22.  
  23.             bitonalBitmap.Save(file, imageCodecInfo, encoderParameters);
  24.  
  25.             MODI.Document doc = new MODI.Document();
  26.  
  27.             doc.Create(file);
  28.  
  29.             doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);
  30.  
  31.             MODI.Image img = (MODI.Image)doc.Images[0];
  32.  
  33.             doc.Close(false);
  34.  
  35.             encoderParameter.Dispose();
  36.             CutImage.Dispose();
  37.             bitonalBitmap.Dispose();
  38.             System.Runtime.InteropServices.Marshal.FinalReleaseComObject(doc);
  39.             GC.Collect(); 
  40.  
  41.             return img.Layout.Text;
  42.         }
Thanks in advance.
Mar 31 '08 #1
1 1723
vanc
211 Expert 100+
The way to get around it is to put all files that need to be deleted in to an ArrayList and when the process that acquires those files stopped. Then you can delete those files easily. :D you can check those files before deleting them to make sure there is no process is locking them. This is not a good idea but it will help. Cheers.
Mar 31 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Pekka Niiranen | last post by:
Hi, I have used the following example from win32 extensions: -----SCRIPT STARTS---- import win32file import win32con import win32security import pywintypes
4
by: Mountain Bikn' Guy | last post by:
I am having serious problems with the following IDE bug: Could not write to output file 'x.dll' -- 'The process cannot access the file because it is being used by another process. ' and BUG:...
18
by: Conrad F | last post by:
Hello all, I am waiting for receipt of files in a directory. I use the FileSystemWatcher to detect when files arrive in said folder. I need to read the data from these files ASAP but the files...
2
by: Raed Sawalha | last post by:
Hello , I have windows service which do listening to specified directory using FileSystemWatcher , on Created Event and Get all the files in the directory using Directory.GetFiles function then...
2
by: Roger Twomey | last post by:
I am working on a filewatcher application. The premis is: User uploads an xml file onto the web server the filewatcher app sees the xml file filewatcher app reads the file and inserts...
13
by: George | last post by:
Hi, I am re-writing part of my application using C#. This application starts another process which execute a "legacy" program. This legacy program writes to a log file and before it ends, it...
5
by: bulldog8 | last post by:
I've read numerous posts and have tried multiple approaches that I found, but just cannot get a file renamed. I am using VB.Net 2002 ... Here is what I have tried: 1) Code common to all...
16
by: Eran.Yasso | last post by:
Hi, I have a mdb file shared in the LAN. I want to write app that verifies if it's open. If the file is not open, then my app can open the file. if the file is used, then the app won't open it....
8
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
Hi; I copied a new set of files over to my ASP.NET dir (and subdirs) on our test server. This replaced every file for the app. When I first then tried to bring it up, I got the below error. ...
0
by: Tim Golden | last post by:
aditya shukla wrote: Why on earth are you *specifying* c:\python25 as the directory for this file? It's automatically created in your user-specific temp directory which has specific permissions...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.