Click here to Skip to main content
15,891,766 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Let the wierdness begin:

I have an app that calls a webservice, it works fine. Opening the application in .net it runs the code that connects to the webservice. How do I know this, well my exceptions are handled through email, I am getting tons of emails with my error messages. No, f5 is not being keyed. Also, when I try to open a form by clicking on it in the solution, bingo; off goes another attempt at trying the webservice. And when I change the code to comment out the EmailException() method and build it, bingo. Another email. REMEMBER: this is in design time, not run time. Any ideas are welcome, since I won't be able to continue work on it until this is resolved. Yes, I already tried exsorcism on the computer :)
Posted

Its pretty simple, somewhere you probably have a custom control or form that you are inheriting from, and in that form you are using some of the events like the OnFormLoad or OnHandleCreated and doing something with your web service.

Design time in .NET must be handled by your code, you need to check if the form or control is in design mode before calling your web service. Design mode isn't something special that shuts down all the background code and events, forms and controls run in design mode just like they do at runtime. Its up to you, the developer, to figure out that you are in design mode and shut down the parts of the code that you don't want to run.

Without seeing your code though, I can't tell you the best way to detect it. Forms and controls have a DesignMode property that is pretty reliable, but you need to do more than one check.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Aug-13 17:07pm    
5ed. DesignMode is really a key to be used to stay out of trouble. Did you see many cases when, during developers or even in some already deployed products, the form cannot be shown under the designer? This is cured by DesignMode.

There is one more, even more important key: not to overuse the designer.

—SA
Ron Beyer 7-Aug-13 17:40pm    
Thanks Sergey, I have run across many a third-party component that couldn't be used design time because the developer was doing database operations or other odd things (like getting the application instance) in the code. Having written a full featured IDE myself I'm all too aware of missing this check and having strange behaviors start popping up (like application background services starting unexpectedly).

The bad part is that there is more than one way to check, first you should check for the Site property not being null, then you can check the LicenseManager.UsageMode, and the DesignTime flag, they give different values at different times depending on what state of initialization the designer is in.
Sergey Alexandrovich Kryukov 7-Aug-13 18:05pm    
Oh yes, those are the invitations for screw-ups...
—SA
Sergey Alexandrovich Kryukov 7-Aug-13 17:09pm    
MainFrameMan_ALIVE_AND_WELL$$:

Your "solution" Solution 2 has been automatically removed, due to member's abuse reports. This is because it's not a solution. And Ron did not get a notification on your post. To get heard, you need to add a comment to this solution.

—SA
Is this code behind a form (be it a windows form or WPF), and are you showing the designer window? This type of behaviour is exhibited in this case because the VS designer actually executes the code for the form when it displays it in the designer window. I know, it sounds daft, but I have seen this behaviour many times when I've hooked up to an interface that would normally be satisfied by DI.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900