Wia 2.0 duplex scanning throw exception "System.outofmemoryException" C#
Asked Answered
M

0

6

I'm using WIA on C#. When I set the properties "pages" to 1 and "docuemnt handling select" to 5 (to enable AFD and Duplex scaning), I get an exception at the method "wiaCommonDialog.ShowTransfer".

The exception is "System.OutOfMemoryExcepion".

Can you help me to fix it? Do I use the right values?

try
{
     SetWIAProperty(device.Properties, "3096", 1);//pages to 1
     SetWIAProperty(device.Properties,"3088",5);//Handling select to 5
     if (init == false)
     {
          init = true;
     }
     wiaCommonDialog = new WIA.CommonDialog();
     while (true)
     {
          object imgFile = (ImageFile)wiaCommonDialog.ShowTransfer(item,WIA.FormatID.wiaFormatJPEG,false);//Here the exception is shown
          object imgFile2=(ImageFile)wiaCommonDialog.ShowTransfer(item, WIA.FormatID.wiaFormatJPEG, false);
          if (imgFile != null)
          {
               imagenes.Add((ImageFile)imgFile);
               leyo = true;
          }
          if (imgFile2 != null)
          {
               imagenes.Add((ImageFile)imgFile2);
               leyo = true;
          }
     }
}
Mcatee answered 27/11, 2018 at 20:17 Comment(8)
Please show relevant code. An MCVE would be good.Crystlecs
Im using interop.wia from Microsoft, at the first transfer the exception is thrown, if i comment the line "SetWIAProperty(device.Properties,"3088",5);" it works but only one side is scaned.Mcatee
Hey Luis. Did you ever find a fix for this issue?Kamal
@Kamal Did you find fix or more information about this problem?Fink
You are calling in a while (true) loop? Do you have other code that exits this loop? Otherwise surely this will run many times, which would indeed use all memory... Do you not need to also dispose of the instance, i.e. wrap in using() statementGrisby
@Grisby this code can't get one loop because always has exception in same place. in real project while(true) will be replaced to good complicated conditions. Look at MCVE stackoverflow.com/help/mcveFink
@Fink How do you know the exception is on the first loop? OP never said that. It is an out-of-memory exception. If it loops over this statement multiple times that may indeed use all the memory available...Grisby
@Grisby coz i have only one picture & use debugger to make shure in itFink

© 2022 - 2024 — McMap. All rights reserved.