Skip to Content
0
Mar 09 at 05:00 PM

Something on a timer is making my COM objects invalid

35 Views Last edit Mar 16 at 07:35 PM 3 rev

Hi experts, I'm writing an order entry front-end for SAP Business One (9.2) in C# with .NET 4.5.1 using Windows Forms. I'm processing events from the sales order form in my main form (F1) and have added a button to bring up a second form (F2) where the user enters line item information. I pass a reference to the main F1 class (ISConfig) to F2 in its constructor so I can access some F1 variables in F2, namely oOrderForm so I can fill in fields on the sales order screen when they hit save on F2. This works fine unless F2 is active too long. If I just let F2 sit there without any clicks or keystrokes and I hit save within 2.5 minutes, everything is fine. If I wait longer before hitting save it errs when setting PaneLevel, mainForm.oOrderForm objects (Items, Mode, PaneLevel, etc) are invalid and show a COMException in the debugger (image below if you can read it). In fact I see this error in all COM objects, not just oOrderForm. Does anyone know of any 2.5 minute default timers? Is there some sort of keep-alive required between my app and SAP or .NET? I am very grateful for any ideas. Thank you.

comexception.png

Code snippets below:

<u>FORM1 code</u>
    public class ISConfig  {
        public SAPbouiCOM.Application SBO_Application;
        public SAPbouiCOM.Form oOrderForm;

... Then in the event handler, oOrderForm gets set
        //********************************************
        // Handle SAP application item events we care about
        //********************************************
        private void SBO_Application_ItemEvent(string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent)
        {
            // Only take events from Order or Quotes forms (139 = Sales Order Form, 149 = Quotation Form)
            if ((pVal.FormType == 139 || pVal.FormType == 149) && (pVal.Before_Action == true))  // Before_Action means SAP hasn't processed it yet
            {
                oOrderForm = SBO_Application.Forms.GetFormByTypeAndCount(pVal.FormType, pVal.FormTypeCount);

... When my button is pressed, instantiate F2 and pass reference to ISConfig
                ConfigLineForm f2 = new ConfigLineForm(this, true);
                result = f2.ShowDialog();

<u>FORM2 code</u>
    public partial class ConfigLineForm : Form
    {
        public ISConfig mainForm;

        public ConfigLineForm(ISConfig f1, bool mode)
        {
            InitializeComponent();
            mainForm = f1;
            addMode = mode;                     // true = add mode, false = edit mode
        }
... then when the user has entered data and clicked Save I try to set the sales order form's pane level to 1
... so I'm sure to have the line item matrix active when I fill in fields
        private void SaveButton_Click(object sender, EventArgs e)
        {
            try
            {
// THIS IS WHERE THE ERROR OCCURS.  oOrderForm.PaneLevel gets a COM exception after 2 minutes and 30 seconds
// of idle time while F2 is displayed
                mainForm.oOrderForm.PaneLevel = 1;      // Set pane to Contact tab where matrix/grid/line items exist
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error setting PaneLevel :" + ex.Message);
                return;
            }

Attachments

comexception.png (16.0 kB)