You cannot temporarily disable a method in C# (or any language that uses a compiler pretty much). It sounds to me like your WndProc is slow and you're trying to speed it up but I doubt that it is going to solve your issue. You mention 2 projects, why does that matter here? I don't believe the # of projects is relevant here so I'm ignoring that aspect.
WndProc
is called whenever Windows needs to send a message to your window (or any control for that matter). This is automatic and cannot be disabled. This is how Windows works. But WndProc
is called many, many times throughout the lifetime of an app and is highly unlikely to slow anything down. It literally just takes the message type and calls an overridable method on the corresponding class. GIven we do this throughout the lifetime of OOP apps all the time this is really fast. I'd wager you'd have to be in the 100s of calls a second before your processor would even remotely notice it. The problem isn't with WndProc
I'm willing to bet.
Without knowing more about your app I'm going to guess at what is going on here. Your code is adding a control to the form and moving it around. Every time you do this it is going to trigger a redraw of the UI and if you're using resizable/anchor/docked controls then they have to have their layout recalculated. This is expensive if you're doing this on the fly (like dragging a control across the window). What you need to do is optimize your logic if this is a requirement.
One approach to fixing this is to set all the properties before adding the control to the parent. Then it only has to adjust the layout once. If you really, really need to make lots of UI changes then call SuspendLayout on the form first. This prevents the form from updating until you are done. This is exactly how the designer-generated code works. The user will see the UI "freeze" while you are doing whatever you're doing but then the form will refresh once.