I have a problem similar to this one: How can I execute code after my form starts?
But the solution there won't work for me because I am not running a form, I'm running a single custom control, which is a tray icon that monitors things. (Similar to the Icon Dropbox has, where that is the only interface the user has with the program)
What should I do to run code when the control is created? (which has to be after the message pump starts)
I think you're looking for the Application.Idle
event.
Occurs when the application finishes processing and is about to enter the idle state.
E.g.
Application.Idle += delegate { Console.WriteLine(Application.MessageLoop); };
// Output: true
Application.Run();
First option would be to post a windows message to yourself. That way it will not be dispatched until your thread starts pumping messages. A second option is to hook into the Application.Idle event which is fired when the message queue is empty. Your third option would be to set and run a Timer for a small duration and hook into the Tick event for when it expires. Fourth and the last for now is to fire a delegate asynchronously as they use the message queue as the mechanism for being fired.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With