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;
          }
     }
}
Uwe Keim
  • 36,867
  • 50
  • 163
  • 268
  • Please show relevant code. An [MCVE](https://stackoverflow.com/help/mcve) would be good. – Gabriel Devillers Nov 27 '18 at 21:46
  • 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. – luis alberto juarez Nov 28 '18 at 17:17
  • 1
    Hey Luis. Did you ever find a fix for this issue? – Zach Jan 04 '19 at 20:20
  • @Zach Did you find fix or more information about this problem? – Jiraff537 Apr 10 '19 at 07:28
  • 2
    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() statement – Milney Apr 15 '19 at 11:24
  • @Milney 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 https://stackoverflow.com/help/mcve – Jiraff537 May 14 '19 at 06:50
  • @Jiraff537 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... – Milney May 14 '19 at 07:50
  • @Milney coz i have only one picture & use debugger to make shure in it – Jiraff537 Sep 19 '19 at 13:23

0 Answers0