McVrsServerMutexMgr error when asynchronous scanning

Discussions about TWAIN & WIA scanning in GdPicture.NET using GdPictureImaging.
Post Reply
Davy
Posts: 1
Joined: Fri May 31, 2019 3:47 pm

McVrsServerMutexMgr error when asynchronous scanning

Post by Davy » Fri May 31, 2019 4:10 pm

Hello,

Recently, our Document Scanning departement request us to be able to add new page to a box in a C# Tools.

So the process is to scan by asynchronous background worker a batch of documents, work on it and add some other document in a second time.

The C# Tools use the recommended way of Doing things.

private BackgroundWorker _backGroundWorker = new System.ComponentModel.BackgroundWorker();
_backGroundWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(m_BackgroundWorker_DoWork);
_backGroundWorker.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(m_BackgroundWorker_ProgressChanged);

public void m_BackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
try
{
IntPtr hwnd = IntPtr.Zero;
if (_gdPictureImaging.TwainOpenDefaultSource(hwnd.ToInt32()))
{
int scanCount = 0;

_gdPictureImaging.TwainSetHideUI(scanProperty.chkHideGUI.Checked);
_gdPictureImaging.TwainSetModalUI(scanProperty.chkModalUI.Checked);
_gdPictureImaging.TwainSetIndicators(true);

if (_gdPictureImaging.TwainIsFeederSelected())
{
_gdPictureImaging.TwainSetAutoFeed(true);
_gdPictureImaging.TwainSetAutoScan(true);
}

do
{
if (!_backGroundWorker.CancellationPending)
{
int imageId = _gdPictureImaging.TwainAcquireToGdPictureImage(hwnd.ToInt32());

if (imageId != 0)
{
scanCount++;
_backGroundWorker.ReportProgress(scanCount, imageId);
}
}
else
{
break;
}
} while (_gdPictureImaging.TwainGetState() > TwainStatus.TWAIN_SOURCE_ENABLED);

if (scanCount > 0)
{
Outils.log.Info("Numérisation finie, " + scanCount + " page(s) acquired");
}
else
{
MessageBox.Show(this, "Le scan a échoué, veuillez consulter les logs.");
}
_gdPictureImaging.TwainCloseSource();
}
else
{
MessageBox.Show("Unable to open the default TWAIN source. " + '\r' + "Result code: " + _gdPictureImaging.TwainGetLastResultCode() +
'\r' + "Condition code: " + _gdPictureImaging.TwainGetLastConditionCode());
}
_gdPictureImaging.TwainUnloadSourceManager(hwnd.ToInt32());
}
catch (Exception ex)
{
Outils.log.Error(ex.ToString(), ex);
throw ex;
}
}

public void m_BackgroundWorker_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
{
try
{
int imageId = System.Convert.ToInt32(e.UserState);
string imageNo = e.ProgressPercentage.ToString();

Thread t = new Thread(() =>
{
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{

string FileName = m_strCheminDocumentScanner + imageNo + m_extension;
gdpictureImaging.AutoDeskew(imageId);
gdpictureImaging.CropBlackBorders(imageId);
gdpictureImaging.FxEdgeEnhance(imageId);
GdPictureStatus status = gdpictureImaging.SaveAsPDF(imageId, FileName, false, "test", "test", "test", "test", "test");
if (status != GdPictureStatus.OK)
{
MessageBox.Show("Erreur en écrivant le fichier " + FileName + ". Status: " + status);
}
gdpictureImaging.ReleaseGdPictureImage(imageId);

}
}
);
t.Start();
}
catch (Exception ex)
{
Outils.log.Error(ex.ToString(), ex);
throw ex;
}
}

When the second _backGroundWorker.RunWorkerAsync() occur a message box popup and the scanned document isn't wrote on the pdf destination folder.

the message :

McVrsServer.McVrsServerMutexMgr(): The Wait completed due to an anbondonned mutex.

My Gdpicture library is on version 14.1.0.20
My VRS is VRS elite 5.1.1
My Framework c# is 4.6

Best regards

Gabriela
Posts: 436
Joined: Wed Nov 22, 2017 9:52 am

Re: McVrsServerMutexMgr error when asynchronous scanning

Post by Gabriela » Wed Jun 12, 2019 10:45 am

Hello,

You can check our Twain Scanning – Asynchronous Sample for such implementation:
https://www.gdpicture.com/guides/gdpicture/web ... 20WIA.html

Gabriela
Posts: 436
Joined: Wed Nov 22, 2017 9:52 am

Re: McVrsServerMutexMgr error when asynchronous scanning

Post by Gabriela » Wed Jun 12, 2019 2:01 pm

Hello,

The issue has been resolved this way:

"Each time a document is scanned, a line that includes the file number is added to a ListView. In order to be able to view the PDF document in a preview control. The lines of code causing the problem of mutex are those:
listViewDocScann.Invoke(new Action(() => listViewDocScann.Items[listViewDocScann.Items.Count - 1].Selected = true));
listViewDocScann.Invoke(new Action(() => listViewDocScann.Select()));
I don't know why selecting a ListView by a delegate to reach the main thread actually loses the mutex.
Hopefully, it can be used for others."

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest