C # execute code after application.run ()

I have a problem like this: How can I execute the code after the form starts?

But the solution there will not work for me, because I do not run the form, I run one custom control, which is a tray icon that tracks everything. (Like the Dropbox icon has, where is the only interface that the user has with the program)

What should I do to run the code when creating the control? (which should be after starting the message pump)

+7
source share
2 answers

I think you are looking for an Application.Idle event.

Occurs when the application ends processing and is about to enter an idle state.

eg.

 Application.Idle += delegate { Console.WriteLine(Application.MessageLoop); }; // Output: true Application.Run(); 
+6
source

The first option is to send a Windows message to yourself. Thus, it will not be sent until your thread starts pumping messages. The second option is to hook into the Application.Idle event, which fires when the message queue is empty. The third option is to set and start the timer for a short duration and connect to the Tick event when it expires. The fourth and last at the moment is to run the delegate asynchronously, since they use the message queue as a mechanism to run.

+4
source

All Articles