NotifyIcon events do not fire

I am new to this and I have a really mysterious problem. I am a software developer in the UK and have over 15 years of experience, but have only been developing in .Net for 18 months. My NotifyIcon mouse events do not fire!

I use C # to write an application that launches as NotifyIcon ("main application icon") and displays the right-click mouse context menu. This works great: ContextMenu, launching forms, and launching mouse clicks.

Tiny background bit: the application must sense the insertion of the USB device (it does), poll it and create another NotifyIcon (device icon) to allow the user to interact with this device. The "main application icon" mentioned in my previous paragraph allows the user to interact with the database and configure the software.

To encapsulate these device interaction features, I built a “device class” that contains the NotifyIcon device, ContextMenu, forms, mouse click events, etc. that allow you to interact with the device.

Problem The problem starts when I create an instance of the "device class" from the EventEriveManagementEventWatcher event. If I create an instance of the device class in my main program, then the events fire correctly when I click on notifyicon.

So please, can someone help me?

Greetings in advance

Matthew

+3
source share
3 answers

IIRC, the use of an event (and not WaitForNextEvent) works async. I would be interested to know in which topic the event takes place. I wonder if there are any message service messages for your icon.

? - ? ( Control.Invoke) - .


; , , . - ; ; , Form ( ) - :

// not a property, as there is no need to add a complex x-thread "get"
public void SetIconVisible(bool isVisible) {
    if(this.InvokeRequired) {
        this.Invoke((MethodInvoker) delegate {
            myIcon.Visible = isVisible;
        });
    } else {
        myIcon.Visible = isVisible;
    }
}

- ( ) . ?

+2

, :

, NotifyIcon , . , , , .

+1

, -

, , NotifyIcon , NotifyIcon (s) , USB-.

, NotifyIcon , , , ( ) Visible true, false - .

ManagementEventWatcher Visible true, .

.

(see answers to your comments)

0
source

Source: https://habr.com/ru/post/1719965/


All Articles