.net events

Posted by Jens Dahlin on 09-Jan-2013 09:11

Where can I find some example code of how to handle .net (non gui) events in ABL?

I'm struggling with error 15740.

"You are trying to use a multi-threaded .NET object in a way that is not supported.  The ABL cannot be called on a thread other than the main thread. (15740)

The ABL is single threaded.  You will see this error if you use a .NET object that employs multiple threads and attempts to call back to the ABL on a thread other than the main processing thread."

Any way to work around this?

All Replies

Posted by jmls on 09-Jan-2013 09:21

What's the control? Are you using this control in a gui screen (even if the

control is non gui)? If so, have a look at the invoke-through method on the

control. That has worked for us in the past.

Julian

Julian lyndon-Smith

IT Director

dot.r limited

Posted by Jens Dahlin on 09-Jan-2013 09:33

Right now its in a simple .p program but eventually it will be in a graphical form of some kind.

The control itself is non gui. A 3rd party dll for communicating with a credit card payment terminal.

I used a simple subscribe with a local procedure as target.

Posted by jmls on 09-Jan-2013 09:46

nsoftware ?

Posted by Jens Dahlin on 10-Jan-2013 00:54

No, provided and supported by a company called Nets. They are a leading payment solution provider in the nordic countries.

Posted by Admin on 10-Jan-2013 01:03

So it looks like this component uses a background thread (not uncommon in .NET).

You'll have to synchronize the background thread event to the foreground thread. I usually write a C# class inheriting from the Control class and use the InvokeRequired and BeginInvoke methods of the Control to raise the event in the foreground thread. And from there on, you can handle your Control's event nicely from the ABL.

Posted by Jens Dahlin on 10-Jan-2013 01:38

Thank you (not really what I wanted though...)

Posted by Jens Dahlin on 10-Jan-2013 01:39

Here you mentioned the same error:

https://community.progress.com/community_groups/openedge_development/f/19/t/1715 

Did you ever find a solution?

Posted by gamerome on 21-May-2013 03:03

Hello,

I don't start new discussion because I have the same problem and I don't know how can I resolve this 15740 error.

You
are trying to use a multi-threaded .NET object in a way that is not
supported.  The ABL cannot be called on a thread other than the main
thread. (15740)

I think you all know the Microsoft Office Interop Word? So...this is what I use...what I try to use!!!

I just want intercept an event from this assembly but this error raise.

If I've well understood, I need to synchronized these two threads (prowin32 and winword). But How can I proceed? There are not BeginInvoke / InvokeRequired methods.

Is there any solution ?

Thanks

Posted by Admin on 21-May-2013 03:11

Is there any solution ?

Not in the ABL. The ABL with GUI for .NET can only handle events from the foreround thread. So you'll have to write a little .NET Assembly yourself (C#, VB.NET) and handle that event there and raise an event to the foreground thread that you can handle in the ABL.

Also, many Com Interop Events don't use event handlers that are compatible to the System.EventHandler delegate. And from the ABL you can only handle those event's that comply. So you'll have to ensure your event fits with System.EventHandler.

Posted by gamerome on 21-May-2013 03:43

Hello Mike,

How can I know if an Interop Event is compatible  to the System.EventHandler delegate?

In my case, I would like to intercept the DocumentBeforeSave event from Microsoft.Office.Interop.Word : http://msdn.microsoft.com/fr-fr/library/microsoft.office.interop.word.applicationevents4_event.documentbeforesave%28v=office.11%29.aspx

Posted by Admin on 21-May-2013 03:46

In my case, I would like to intercept the DocumentBeforeSave event from Microsoft.Office.Interop.Word : http://msdn.microsoft.com/fr-fr/library/microsoft.office.interop.word.applicationevents4_event.documentbeforesave%28v=office.11%29.aspx

I would say it is not. I needs to have the parameters here: http://msdn.microsoft.com/en-us/library/system.eventhandler.aspx

Posted by gamerome on 21-May-2013 05:06

Ok. But If I write a C# dll to intercept this event, could I invoke a internal event of this dll with this prototype? And thanks to that, ABL will be able to intercept this final event.

Hope you will understand my thought.

This thread is closed