VS2013 and 9.2.2
We need to communicate with a large group of devices via TCP/IP (around 100 card swipe units on various gaming units). These will be randomly used throughout the day based on customer activity, so we need to listen to all of them simultaneously. Most of our application is written in AcuCOBOL compiled with and running on "extend 9.2.2 + ECN-4266". We tried setting up threads within the runtime to listen for this input, but the CPU usage shot up to 100% after just trying to listen to 2 or 3 units.
I'm writing a desktop app using "Visual Studio 2013 Express for Windows Desktop" with BackgroundWorker threads for each TCP/IP communication connection to keep the user I/O responsive. I have a COBOL program (CardNet) that will take input from the VS program and handle the file I/O and business logic and send a response back to the unit (pass/fail, remaining balance, trigger tokens, etc.).
I compiled the COBOL program using the following: D:\ACU922\ccbl32 -Ds -Za -lfo NetLFO.txt --netdll CardNet
I copied both CardNet.dll and CardNet_CVM.dll to the VS source folder and added CardNet_CVM.dll to the project as a reference. I copied the object file (CardNet.acu) to my CODE-PREFIX folder.
The VS source (Form1.cs) has "using CardNet_CVM;" at the top.
In the "public partial class MainForm : Form" section I've declared "CardNet_CVM.CVM cblObj;"
In the "MainForm()" section, I use GetCommandLineArgs() to check for a "-c" argument so I can specify a cblconfig file at run time. If found, I set the next argument to a string variable called "cblconfigFile".
In the "MainForm_Shown()" section, I have the following:
cblObj = new CardNet_CVM.CVM();
if (cblconfigFile.Length == 0)
logTextBox.AppendText("Initialize AcuNet..." + Environment.NewLine);
logTextBox.AppendText("Initialize AcuNet using:" + cblconfigFile + "..." + Environment.NewLine);
catch (System.Exception e2)
Exception e3 = e2.InnerException;
string errorMsg = "";
if ((e3 != null) && e3.Message.Length > 0)
errorMsg = e3.Message.Trim();
else if (e2.Message.Length > 0)
errorMsg = e2.Message.Trim();
logTextBox.AppendText("AcuNet initialization failed. " + errorMsg + Environment.NewLine);
In the "MainForm_FormClosing()" section, I have "cblObj.ShutDown(0);"
Everything appears to be working properly while the program is running. I get data from a swipe, pass the data to the COBOL program and get the expected response back to pass along to the swipe.
The problem is when I close the application, I get "unhanded exception of type 'System.Runtime.InteropServices.SEHException' occurred in System.Windows.Forms.dll. External component has thrown an exception."
I commented out all the lines dealing with the runtime, then started adding them back in until I got an error on program exit. I can include the "using" line, declare the cblObj and create the object using the "new" line (before the "try") and the program will exit without the exception. Once I include the "cblObj.Initialize()" call (with or without specifying the cblconfig file), I get the exception on exit. It doesn't matter if I include cblObj.Shutdown in the FormClosing section or leave it commented out.
When the exception is thrown, VS highlights the "Application.Run(new MainForm());" line in the "Program.cs" file.
I am compiling both the VS project and the COBOL dll from a computer running Windows 7 Pro with SP1. I'm also running the VS program on the same computer.
I searched on Google for the error. The results point to various 3rd party programs being called from / used within a VS program.
Any ideas on why the runtime is throwing an exception when I try to exit the program? Is there something I'm missing in the COBOL compile line or how I'm including and using it in the VS project?
Bookstore Manager, Inc.