Click here to Skip to main content
16,005,473 members
Home / Discussions / C#
   

C#

 
AnswerRe: Why C# doesn't have macro like C++ Pin
DaveyM698-Jan-09 0:57
professionalDaveyM698-Jan-09 0:57 
GeneralRe: Why C# doesn't have macro like C++ Pin
Gopal_Kanchana8-Jan-09 1:13
Gopal_Kanchana8-Jan-09 1:13 
AnswerRe: Why C# doesn't have macro like C++ Pin
Lev Danielyan8-Jan-09 1:10
Lev Danielyan8-Jan-09 1:10 
GeneralRe: Why C# doesn't have macro like C++ Pin
Gopal_Kanchana8-Jan-09 1:12
Gopal_Kanchana8-Jan-09 1:12 
AnswerRe: Why C# doesn't have macro like C++ PinPopular
#realJSOP8-Jan-09 1:12
professional#realJSOP8-Jan-09 1:12 
GeneralRe: Why C# doesn't have macro like C++ Pin
Jon Rista8-Jan-09 7:04
Jon Rista8-Jan-09 7:04 
AnswerRe: Why C# doesn't have macro like C++ Pin
Dave Doknjas9-Jan-09 15:11
Dave Doknjas9-Jan-09 15:11 
QuestionWindows Service Gotcha [modified] Pin
#realJSOP7-Jan-09 23:56
professional#realJSOP7-Jan-09 23:56 
This is not a question, but is too short to be an article. Learn from my mistake.

Yesterday, I was testing a windows service I wrote using Visual Studio 2008 on a Windows 2000 machine. I had originally targeted .Net 3.5 when I created the project, and had to re-target the assemblies to 2.0 before installing it on the target machine. When I installed it, the event log would say that the service started successfully, but a few seconds later, I would get an error event - an invalid operation exception.

I removed EVERYTHING from the service except a keep-alive thread so it would keep running once installed, and it still threw the exception.

Thinking it might e a flaw in VS2008 when changing from .Net 3.5 to .Net 2.0, I tried creating an entirely new solution targeting .Net 2.0 from the start. It still threw the exception. And then I had an epiphany.

The installer class sets the name of the service. One thing that all windows services do (when you create them with the VS2008 template) is calls the InitializeComponent() method. I had always deleted this call in prior services I had written since it seemed like a pointless thing to do, but this time, I had left the call in. In InitializeComponent, it tries to set the service name to "Service1". This is NOT the name I gave it in the installer object. After changing the name to the same thing I used in the Installer object, it worked just fine - no exceptions.

When I changed the name of the service.cs file, I guess it missed that string in the re-factoring process. I spent four hours on this problem. BTW, the other fix for this would have been to NOT call InitializeComponent.

[EDIT] BTW, I had tested this service on my own Vista box, and it worked fine. While I was waiting for access to the Win2K box, I figured I'd fix the Service name (because it was showing up as "Service1" in the event log). I re-factored and compiled, but did not re-test it before trying it on the Win2K box (I figured the re-factor would have done what it was supposed to do). The lesson here? ALWAYS RE-TEST, NO MATTER HOW MINOR THE CHANGE IS PERCEIVED TO BE. This is proof that even the programmers with 30 years in the industry make the most rookie kind of mistakes every once in a while.


"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001


modified on Thursday, January 8, 2009 7:25 AM

AnswerRe: Windows Service Gotcha Pin
EliottA8-Jan-09 2:34
EliottA8-Jan-09 2:34 
AnswerRe: Windows Service Gotcha Pin
Le centriste8-Jan-09 3:28
Le centriste8-Jan-09 3:28 
AnswerRe: Windows Service Gotcha Pin
PIEBALDconsult8-Jan-09 12:40
mvePIEBALDconsult8-Jan-09 12:40 
QuestionC# Forms Panel Scrolling Pin
musefan7-Jan-09 23:53
musefan7-Jan-09 23:53 
AnswerRe: C# Forms Panel Scrolling Pin
#realJSOP7-Jan-09 23:57
professional#realJSOP7-Jan-09 23:57 
GeneralRe: C# Forms Panel Scrolling Pin
musefan8-Jan-09 0:00
musefan8-Jan-09 0:00 
GeneralRe: C# Forms Panel Scrolling Pin
#realJSOP8-Jan-09 0:15
professional#realJSOP8-Jan-09 0:15 
GeneralRe: C# Forms Panel Scrolling Pin
musefan8-Jan-09 0:33
musefan8-Jan-09 0:33 
GeneralRe: C# Forms Panel Scrolling Pin
Dave Kreskowiak8-Jan-09 4:39
mveDave Kreskowiak8-Jan-09 4:39 
GeneralRe: C# Forms Panel Scrolling Pin
musefan8-Jan-09 4:57
musefan8-Jan-09 4:57 
GeneralRe: C# Forms Panel Scrolling Pin
#realJSOP8-Jan-09 5:55
professional#realJSOP8-Jan-09 5:55 
GeneralRe: C# Forms Panel Scrolling Pin
musefan8-Jan-09 6:12
musefan8-Jan-09 6:12 
GeneralRe: C# Forms Panel Scrolling Pin
Jon Rista8-Jan-09 7:06
Jon Rista8-Jan-09 7:06 
GeneralRe: C# Forms Panel Scrolling Pin
musefan8-Jan-09 22:13
musefan8-Jan-09 22:13 
QuestionWhat's the best way to check that Pin
CodingLover7-Jan-09 23:46
CodingLover7-Jan-09 23:46 
AnswerRe: What's the best way to check that Pin
Lev Danielyan7-Jan-09 23:55
Lev Danielyan7-Jan-09 23:55 
NewsRe: What's the best way to check that Pin
CodingLover8-Jan-09 0:04
CodingLover8-Jan-09 0:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.