winforms icon indicating copy to clipboard operation
winforms copied to clipboard

Make Application.[Begin,End]ModalMessageLoop() public instead of internal

Open rickbrew opened this issue 3 years ago • 7 comments

I must admit that I've been using these two methods, via reflection, for ... a very, very, very long time (15 years?). Paint.NET relies on them in order to create something called a modal frame, which is where the UI is doing some kind of processing, e.g. loading (an) image(s) and showing a progress bar in the status bar, and needs the UI to stay not-un-responsive (not ghosted, i.o.w.), but also to be disabled but not visibly disabled (i.o.w., no input allowed, but don't change appearance). There's also some other weird (yet also very important!) places I use it, but that suffices for now.

As far as I can tell, this isn't achievable without resorting to reflection to call these two methods. At this point, even if someone has a better way of doing this, I'm not sure the risk is worth it because it could fundamentally break the app if even one tiny part didn't work in exactly the same way (the modal frame also involves some weird, esoteric message pumping stuff).

So I have 2 requests, mutually exclusive. Either 1) don't ever change these methods, as it'll fundamentally break Paint.NET, or 2) just make them public. Happy to craft up a PR for the second :)

rickbrew avatar Jan 27 '22 01:01 rickbrew

We'll pick up this proposal at an upcoming review meeting in the team.

merriemcgaw avatar Feb 24 '22 23:02 merriemcgaw

Thanks @merriemcgaw ! Some of the details of this are lost to time, but I'm happy to dive back into the code to figure it out if it helps. The code/solution is also available for MSFT employees if you need to take a peek. AFAIK there could even be a way for me to accomplish what I need without these methods. (And, it's not that I need these methods, but I need what they provide me -- alternate API is fine of course)

rickbrew avatar Feb 25 '22 00:02 rickbrew

@rickbrew I don't see any realistic way to do this without making these public (or making further risky changes). If you want to turn this into a formal proposal I'll submit it for API review. You can look at the .NET runtime example for the structure of this: https://github.com/dotnet/runtime/issues/38344

Please also put your first stab as to what the XML comments should be (based on the other MessageLoop APIs).

@RussKie the runtime has a nice template for this now, would you be able to add one for our repo?

JeremyKuhne avatar May 27 '22 17:05 JeremyKuhne

the runtime has a nice template for this now, would you be able to add one for our repo?

We already have it. Feel free to tweak it, if you think it is necessary.

RussKie avatar May 30 '22 03:05 RussKie

This submission has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 14 days.

It will be closed if no further activity occurs within 7 days of this comment.

ghost avatar Jun 13 '22 04:06 ghost

@JeremyKuhne wow that looks like a lot of work to write up a proposal, especially since my knowledge of this area is from 10 years ago and I'd have to page it all back in (and I'm currently very busy on some other work at the moment). I understand the need to have a formal process for important things like making a private method into a public API, but all I really need at this time is a promise that it won't be changed, removed, or broken. Even just adding a comment to the WinForms code like, // NOTE: AppCompat: don't remove/change without looking at GitHub Issue #6555 first would probably be sufficient. Is that something that can be accommodated? It would literally break my app if this area were changed, with no viable way of reimplementing the functionality.

rickbrew avatar Jun 13 '22 17:06 rickbrew

@rickbrew the only real way to ensure that we keep compatibility is to make it officially public. That's our guarantee mechanism. That said, the likelihood of us changing this is pretty low, so there isn't a lot of pressure on going through the API process. The only advantage of rushing is that you get the ability to use the public API sooner rather than later.

Filling out the template isn't as hard as it might seem at first. To do a good job I've found it is about an hour or two (including having enough XML comments to generate reasonable docs).

All this said, if you want to create a PR with a comment linking to this issue I'm happy to take it. Given that you need this there are likely to be others that could use this as well, so I'd be happier to see this ultimately become public as opposed to just linking to this issue in the comments.

JeremyKuhne avatar Jun 13 '22 17:06 JeremyKuhne