Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

How to fire evet from static-method

$
0
0

Hi

I have C# class including events interface. The class instance is targeted to be used in VBA.

The class has Read Thread static method which calls OnMyEvent non-static method to fire

MyEvent.

      public static void Read()  // must be static
        {
            while (_continue )
            {
                try
                {
                    if (_init)
                    {
                        RxData = _serialPort.ReadLine();
                        OnMyEvent(RxData);  // <<<<<<<<<<< Error: An object reference is required for the non-static field, method, or property 
                     }
                }
                catch (TimeoutException) { }
            }
        }

I searched the WEB but nothing solve  my issue. I  tried :

Singleton  (but i have to "new" in VBA)

pass arg by ref does not do it (same error)

create new class instance (_inst.MyEvent) does not work

The said Error moves around as i try to modify methods to non-static

What do i do ?

Your help will be appreciated

Thanks


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>