How to deal with the background tread in .Net and raise the

Posted by PeterWokke on 27-Nov-2015 05:54

Have found a guiding on the net to deal with the following:

Dealing with serial port .Net object to forward the ReadLine to raise the event in the foreground tread without crash the AVM.

But cannot find source code examples how to do this.

Who know and want to share this?

Kind regards,

Peter Wokke

All Replies

Posted by Mike Fechner on 27-Nov-2015 06:00

You're willing to build your own C# assembly? Because it requires .NET code.

A .NET Control is able to raise an event from a background thread in the UI thread. Code looks like this, in a class inheriting from Control. This code will raise the event from the foreground thread when already running there and switch to the foreground thread if required - in the ABL you put that Control on a Form (might be a very small Control):

        protected void OnDataAvailable (EventArgs e)
        {
            if (this.InvokeRequired)
                this.BeginInvoke(new Action<EventArgs>(OnDataAvailable), new[] { e });
            else
                this.DataAvailable(this, e);
        }

Posted by PeterWokke on 27-Nov-2015 06:20

Mike,

Thank you kindly for your guiding.

I am working and a C# assembly to deal with the read options on the serial port.

Now I run on an error that multi-treating is not supported in ABL .Net.

Will work on this and see what happens.

Regards, Peter

Posted by PeterWokke on 27-Nov-2015 06:20

Mike,

Thank you kindly for your guiding.

I am working and a C# assembly to deal with the read options on the serial port.

Now I run on an error that multi-treating is not supported in ABL .Net.

Will work on this and see what happens.

Regards, Peter

Posted by OctavioOlguin on 28-Nov-2015 14:17

I'm using mscomm32.ocx, on non .NET frame, but it allows me to send some code on the port, and then wait for the weight scale to answer...(even installed on syswow64 dir of a win64).

Isn't this something that can help you?

Posted by PeterWokke on 30-Nov-2015 01:26

Hello Octavio,

The mscomm32.ocx is an 32bit DLL that I cannot load in a 64bit Progress AppBuilder session.

Now I have to find out hou to create an ABL .Net class inheriting from control.

Other option id to load the kernel32 in C# and access the comm port based on this kernel32.

King regards,

Peter

Posted by cverbiest on 30-Nov-2015 03:09

Hi Peter,

Totally beside your original question but I try to avoid serial communication in OpenEdge completely.

When confronted with a serial device we try to hook it up to a Moxa serial device server that  turns serial into socket communication.

www.moxa.com/.../index.htm .

PS: I have no shares in Moxa ;-)

Posted by OctavioOlguin on 01-Dec-2015 14:48

Peter.. you can use mscomm32 in win64....

put the ocx in sysWOW64 directory and register  (regsvr32) from there....

and that's it...

Posted by Mike Fechner on 01-Dec-2015 14:52

You can use 32 bit DLL's or Active X's in 32 bit apps on Windows 64 bit yes.

But you can't use 32 bit DLL's or Active X's in 64 bit apps. So your trick won't work for 64 bit versions of OpenEdge.

Posted by OctavioOlguin on 01-Dec-2015 14:56

And for maintenace i try not to open in uib, just the editor.... (matter of fact, 15 years ago I build that interfase in V9) and only once I had to add field to show activity...

trying to post....

Posted by OctavioOlguin on 01-Dec-2015 14:58

sorry.

missed wrx

please rename to mfq-40.wrx

Posted by christian.bryan@capita.co.uk on 08-Nov-2017 12:37

You will need to Invoke the event on the main thread in your c# DLL.

E.g

//Declare a dispatcher

private Dispatcher _uiDispatcher; // This will be the UI Dispatcher which runs on the main the

// Get the UI Thread Dispatcher important as we need to dispatch this event on the main thread

_uiDispatcher = Dispatcher.CurrentDispatcher;

When it comes to raising the event.... and you are not on the main thread invoke...

// Are we on the GUI thread?

               if (Dispatcher.CurrentDispatcher != _uiDispatcher)

               {

                   _uiDispatcher.Invoke(OnCSSConversationAdded, this, myConversationAddedEventArgs);

               }

               else

               {

                   OnCSSConversationAdded(this, myConversationAddedEventArgs);

               }

This thread is closed