|
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?
|
|
|
|
|
|
It's one of the controls present on my form.
|
|
|
|
|
hm..this is only true for me if the panel fills out the whole form.
you could set a flag on the form's SizeChanged event like this
bool resizing = false;
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
if (!resizing)
MessageBox.Show("MouseUp");
}
private void Form1_SizeChanged(object sender, EventArgs e)
{
resizing = true;
}
|
|
|
|
|
buchstaben wrote: private void Form1_SizeChanged(object sender, EventArgs e)
{
resizing = true;
}
And where do you ever set that false?
|
|
|
|
|
okay, but this spectaculous pimp would fix it..
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
if (!resizing)
MessageBox.Show("MouseUp");
else
resizing = false;
}
|
|
|
|
|
buchstaben wrote: okay, but this spectaculous pimp would fix it..
But it's still not right
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
if (!resizing)
MessageBox.Show("MouseUp");
resizing = false;
}
That should work tons better
|
|
|
|
|
I already have a lot of constants with me. I have managed to overcome the issue with those.
But I would like to know reason behind it.
|
|
|
|
|
Can anyone suggest a good way to tell if a file is a text file rather than a binary file? I want to search and replace some text in all text files but to ignore binary files.
Thanks
|
|
|
|
|
EXTENSION
If You win You need not Explain............
But If You Loose You Should not be there to Explain......
|
|
|
|
|
The easiest is to check for new line characters.
Some binary may contains the newline character(s), in that case you will have to analyze the line a bit more. Obviously a very long line hints to binary.
Also check for control characters, those from 0 to 31 (i think), with a few exceptions of course.
Good luck
|
|
|
|
|
williammorrishooper wrote: I want to search and replace some text in all text files but to ignore binary files.
hm..not sure if it's worth the effort.
say you want replace "mystring1" with "mystring2". There would be no match in any of your binary files, wouldn't?
Or is it more a performance issue?
|
|
|
|
|
Not really, binary file can contain that series of text, no?
|
|
|
|
|
Hi,
I have a COM object that accept an array of integer.
HRESULT __stdcall CTestCOM::setValues(int* arr, int arrSize)
{
for(int i=0; i<arrSize; i++)
{
MyDebugTextOut("C:\\Temp\\TestCOM.txt", "arr[%d] = %d\n", i, arr[i]);
}
}
In my C# code:
int[] arrTest = new int[5];
for(int i=0; i<5; i++)
{
arrTest[i] = i;
}
TestCOM testCom = new TestCOM();
testCOM.setValues(ref arrTest[0]);
The result of my text out in x86 is correct:
arr[0] = 0
arr[1] = 1
arr[2] = 2
arr[3] = 3
arr[4] = 4
arr[5] = 5
But in my x64, it is wrong:
arr[0] = 0
arr[1] = -321451
arr[2] = -14537642
arr[3] = 0
arr[4] = 0
arr[5] = 0
I've checked the address of the array, in x86, it pass a same address from C# to COM object. But in x64, address of the array in the COM object is different from C# array.
Any idea why? If yes, is it possible to fix it?
Thanks
|
|
|
|
|
Although I do not know COM interop, there are a lot of things wrong here...
RYU^^ wrote: testCOM.setValues(ref arrTest[0]);
Why are you passing the reference to the first element in? A .NET array isn't just a int buffer! If you fixed it, then maybe you can use it. (does COM not require you to pass the length parameter too?)
RYU^^ wrote: arr[5] = 5
Your array length is only 5, so how can you read the 6th element?
|
|
|
|