|
Its a pleasure, did it work?
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Sorry I was out of here for sometime. And thank u that did work. I turned off the firewall of that pc. Now it's working.
Thank u once again
|
|
|
|
|
|
|
Hello everyone,
Here is my OnStop method of Windows service application. When click stop, the error message is, "Error: 1067 The process terminated unexpectedly".
I have tested if remove the Join method, the service can stop gracefully. Does it mean Join method is not allowed to be called in OnStop method of a Windows service? Any ideas?
protected override void OnStop()
{
MyWorkerThread.Join();
this.ExitCode = 0;
}
thanks in advance,
George
|
|
|
|
|
It could be because your worker thread never ends. Did you tried to use the Join method with a timeout parameter?
What are you doing in your worker thread?
|
|
|
|
|
Hi Zoltan,
I have tried with Join(500), still failed. My worker thread is very simple,
it looks like. Any ideas?
The main thread will set stop status, then join the worker thread.
while (true)
{
}
regards,
George
|
|
|
|
|
static volatile bool running = false;
...
running = true;
while (running)
{
}
That should give you the idea
|
|
|
|
|
Thanks leppie!
I think the differences is your code is using volatile and my code is not?
What will be the impact if I do not use volatile in my scenario?
regards,
George
|
|
|
|
|
Not really, or at least I dont think so, I guess it depnds how tight your loops is, either way, if it goes false, it will stop. Does it matter if it does another loop? Probably not.
|
|
|
|
|
I have tried to change to volatile. Not working, strange. Still service stop fail. Any ideas?
regards,
George
|
|
|
|
|
I think the while-sleep method is not the best to check if a thread must stop. You should be using waithandles for that.
Anyway try something simple in your worker thread, and try to isolate the bug.
|
|
|
|
|
Thanks Zoltan,
Do you mean using sleep method will cause service stop error -- as I mentioned in my original question?
regards,
George
|
|
|
|
|
This is the (simplified) body of most thread functions I use in my services...
ServiceController controller = new ServiceController(this.ServiceName);
while (true)
{
if (controller.Status == ServiceControllerStatus.Running)
{
Thread.Sleep(4500);
}
}
"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
|
|
|
|
|
Thanks John,
1.
I have tried your solution can work. My fix code is, leaving OnStop method empty, and the worker thread will sleep 2 seconds, do some work and check whether the controller's status is not Runnning, if not Running, I will stop the worker thread. Is my solution correct?
2.
I think in this solution, the main thread will stopped at first when we choose to stop the service, then the worker thread will stop later, when the main thread exits the OnStop service (when the controller's status is not Runnning)?
3.
If the answer to 2 is yes, my question is, the worker thread in a Windows service is allowed to be stopped after the main thread?
regards,
George
|
|
|
|
|
1) Yeah, it would look something like this:
ServiceController controller = new ServiceController(this.ServiceName);
while (true)
{
if (controller.Status == ServiceControllerStatus.Running)
{
Thread.Sleep(2000);
}
if (controller.Status == ServiceControllerStatus.Running)
{
}
}
If you want decent response times, you should probably always check to see if the service is running before sleeping or doing work.
2) You shouldn't have a problem with the order in which threads are stopped unless you spawn a thread that relies on the results generated by threads it spawns.
3) If you're concerned about it, you can use set/get this.CanStop . So, at the top of your thread function, do this:
this.CanStop = false;
and at the end (or before your exit from the thread function), do this:
this.CanStop = true;
Keep in mind that if you're running multiple threads, this won't really work well, and you'll have to setup a similar but different mechanism.
"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
|
|
|
|
|
Thanks John,
I found when using administrator account to run the service, everything is fine. So I think it may be the issue of using NT AUTHORITY\Network Service account, which is not granted enough privilege.
Now I am going to try to reproduce this issue, my current question is, when assign the log-on account back to NT AUTHORITY\Network Service, and clicks ok in SCM, there is an error message which indicates me to input a correct password for NT AUTHORITY\Network Service.
But I do not know the password for this account. And I want to reset the password for NT AUTHORITY\Network Service.
How to reset the password for this account? Normally to any other account in the Windows server 2003? I have this question is because I noticed a couple of the Windows Services on my local computer is using this account to log on, I do not want to impact other services when changing the password for account NT AUTHORITY\Network Service.
Any comments?
regards,
George
|
|
|
|
|
HI, i'm loking to do this :
byte a;
bool [] Array;
array = a;
in Order to parse the byte to bool;
i've tried to use BitArray like this :
string dataMsg = null;
BitArray aArray = new BitArray(a);
for (int i = 0; i < 8; i++)
{
if (aArray .Get(i))
{
dataMsg += "1";
continue;
}
dataMsg += "0";
}
but it always gives me "01010101" -> Strange
where did i gone wrong, Help
Have Fun
Never forget it
|
|
|
|
|
|
No, it's 255
But I've Got it, Thanks AnyWay
Like This:
Byte a;
bool Temp_Bool = (((a >> i) & 1) ==1 )?(true):(false);
Have Fun
Never forget it
|
|
|
|
|
half-life wrote: bool Temp_Bool = (((a >> i) & 1) ==1 )?(true):(false);
Another case of the "x?true:false" antipattern...
bool Temp_Bool = (((a >> i) & 1) == 1);
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi!
I have a C# program running with a 3rd party dll version 3.5... When I run it on another machine, having another program with same dll, but version 3.8, I have lots of troubles when the other application has started before then mine.
How can I force my application to load the dll version 3.5?
Thanks a lot
Life is not short... the problem is only how you organize yourself
|
|
|
|
|
You can set those options in the app.config. That said, there should be no interference between 2 version of a dll. What kind of problems do you have?
|
|
|
|
|
It's a little bit difficult: it's SAP :-S ...
SAP has an addon wich work in the directory \root ... under root you can find all the dlls used by this addon...
I'm programming an addon of the addon (called 1staddon) ... and by default all my dlls should reside in \root ... To avoid others addon to overwrite our dlls with the same name, we decided to put our dlls in \root\mydir ...
The problem is that 1staddon loads \root\a.dll and than calls my addon ... but my addon needs to use \root\mydir\a.dll, which is not loaded coz there is already \root\a.dll.
Life is not short... the problem is only how you organize yourself
|
|
|
|
|
This thing has totally stumped me. When I maximize the form, MouseUp event of the panel is firing. It happens only when I maximize the form by double clicking form border. The event is bound just with the panel. Can anyone help regarding this?
|
|
|
|