|
No, actually I don't care *lol*
It's up to my customer if he want to stop the service and maybe lose data.
|
|
|
|
|
The point is that when your service is asked to stop, you shouldn't be concerned about what the in-progress actions of the service are. Your job is to shut down cleanly as soon as you can. Next time the service is started, you can resume or restart any actions that were in progress (obviously, resume is better, but takes more work to make it function correctly).
|
|
|
|
|
Windows expects a service to stop in a certain amount of time. I thought it was only 30 seconds.
If not then windows reports an error however it does not stop anything.
So you have several distinct problems.
1. Do you really want the user to wait 3 minutes for the service to stop? What if your process starts taking longer and it takes 15 minutes?
2. If you do want your users to wait that long then you must educate them. Because some of them will figure out that they can kill the service.
3. What if your secondary process becomes blocked and never returns? What does the user do then?
4. Documentation would suggest that RequestAdditionalTime should work however I doubt it will work like you have it set up. You can't just blast it endlessly. I wouldn't be surprised if your code just makes it hit a limit far before your code is done and so windows just ignores it.
If RequestAdditionalTime doesn't work then there is at least one other API which you can find by googling on the topic. You might or might not need interop to access it.
To use RequestAdditionalTime in a reasonable way I would do it as follows.
1. Set up a loop which sleeps for a small interval and checks for completion of the process. If complete exit. This runs for 20 seconds.
2. Set up a loop which sleeps for a small interval of time, say 5 seconds, checks for process completion and if not complete call RequestAdditionalTime with 5000, then loop again. If the process finishes then exit. This runs for a configurable amount of time. If that amount of time is exceeded then exit regardless of whether process is complete or not.
Note that via experimentation I have found that one MUST call Exit() to insure that all threads are stopped when a service exits.
|
|
|
|
|
can you use Thread.Sleep(40000); onstop Event
|
|
|
|
|
Dear Community
I have written several control-related classes (eg, Symbol, Curve) that store drawing-related information such as line colour, dash style, line thickness, &c in a System.Drawing.Pen property. It is very convenient in code, but in the designer property grid it does not expand and is greyed out.
I have carried out some research and found what is to be done when it is a custom class I want to expand in the property grid ( http://msdn.microsoft.com/en-us/library/aa302326.aspx[^] ), but it is of no help to me as what I use is a built-in type, not my own class.
First of all, do you think it is worth some further ado, or is what I do (simply exposing the System.Drawing.Pen with which I draw the object) considered bad practice?
If it is bad practice, what would you suggest as an elegant solution?
If it is not, how can I make it expand properly in the property grid and be editable?
Thank you very much for your assistance.
Yours faithfully
Tethered Sun
|
|
|
|
|
AFAIK, there is no property-editor for the pen-class; it consists of a brush, a color, a dashstyle and more. Which of the properties of the pen do you want to expose in the PropertyGrid ? Perhaps you could bind those, as opposed to the entire class.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you for your response.
Basically exposing all properties of Pen makes sense for me, as they all control the appearance of the line I should like to draw.
When I started, I was just interested in colour and width. Then came the need for controlling dash style, and exposing the whole Pen allowed me to accomplish that without adding a single line. I do find this convenient, apart from its behaviour in the property browser.
|
|
|
|
|
In that case, you'd prolly have to write your own property-editor. There's a short example here[^]. Benefit is that you can create it exactly as you need it, include all the properties you'd want.
Play a day with the code, it looks harder than it is
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you very much!
I'll do that. Thanks again.
|
|
|
|
|
You're welcome
|
|
|
|
|
Hello,
I am trying to communicate with a Cognex data matrix scanner which is connected to the PC via USB, emulating a COM port. I can open the connection and send commands to the scanner (which is reacting on the commands), but I do not receive any data from the port.
For getting started, I used an example from the MSDN
(http://msdn.microsoft.com/de-de/library/system.io.ports.serialport.aspx[^]) which I simplified and adjusted for the device:
_serialPort = new SerialPort();
_serialPort.PortName = "COM4";
_serialPort.BaudRate = 115200;
_serialPort.Parity = Parity.None;
_serialPort.DataBits = 8;
_serialPort.StopBits = StopBits.One;
_serialPort.Handshake = Handshake.None;
_serialPort.NewLine = "\r\n";
_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;
_serialPort.Open();
I also tried to use the DataReceived and the other events - but also no response. I wrote a small C++ app to use the Win32 api directly but no response either. I downloaded several example applications - but still no response.
The scanner, however, works with the manufacturer application - I therefore downloaded the trial of "Advanced Serial Port Monitor" to see the communication. Interestingly, with this program I am able to communicate with the device and to receive data as expected - but I don't know what is different...
Alex
|
|
|
|
|
Had exactly that problem send, but no receive of data with a spectrum analyzer. I found it was due to an incorrectly set HandShake property I had it as none it should have been 1. Much confusion all that had happen was a change from wired 9 way to USB. My advice is to play around with the HandShake, StopBits, Parity & NewLine just to see if that makes any difference. Try copying across the Advance Serial Port Monitor settings to see if that makes a difference.
Glenn
|
|
|
|
|
Thank you for your answer.
The settings are exactly the same as in Advance Serial Port Monitor as well as the manufacturer application. Indeed, it makes no difference if I change any of these settings except for the NewLine string (when I change this setting, the commands are not accepted any more).
Perhaps the settings do not play any role because the COM port is only "virtual"? The device is connected to an USB slot, where the communication is handled by windows. However, still no response with SerialPort ...
Alex
|
|
|
|
|
There shouldn't be any problem with the device being virtual and interfacing to Visual Studio, my current project is using a Virtual Comm Port, and the FSH3 I referred to was virtual on the USB ( & used Handshaking.None the 9way Dtype used HandShaking.Even). Can I suggest using Jan Axelson's code at www.lvr.com as this I have found does it properly (not that your code is not proper it's just without seeing it...) . It is odd Advanced Serial Port Monitor can send and receive data if it was only the manufactures program I would start to wonder if they had done a trick to prevent others from writing software to interface to it!
Glenn
|
|
|
|
|
I finally found the cause:
I have to set
_serialPort.DtrEnable = true;
and it works - I receive the expected data.
However, I am still wondering why this is not done in typical other examples?
Alex
|
|
|
|
|
That's good, now have you done the Happy Dance! as in the "It works, Hurah!!"
DTR or Data Terminal Ready some times needs to be set high on RS232 to allow the port that there is data there. Not really used that much these days I have used the DTR & CTS lines to supply power to some (smallish) circuits you can also use them as signal lines as you can control the on / off states via the true / false property (I have used the to control LED's & Relays). Good on you for finding that can I suggest the book Serial Port Complete by Jan Axelson (ISBN 978-1-931448-06-2) as a good reference (her other books are good too!, if you want to start hanging stuff out of your PC!)
-=-=-=-=-=-=
Also just though if the piece of hardware is a 'modern' version of an older bit of hardware it could be that the software was designed to alter DTR & CTS to send and receive data on the go and when the USB version of the hardware came about it was easier to bodge some thing like setting a pin high on the port than rewrite the software.
Glenn
modified 24-Aug-12 5:58am.
|
|
|
|
|
what is the code of cheeckbox in c# windows application and what is the use of chekbox in c#.
|
|
|
|
|
You can find all the code you need in the examples found at MSDN - it's one of the simpler controls to use. A checkbox is used to allow a user to select more than one option from a list of several. This contrasts with a radio button, which allows only a single selection from a group of options. A radiobutton is exclusive, while a checkbox is inclusive of a set of available options.
Will Rogers never met me.
|
|
|
|
|
A checkbox allows a user to toggle between two options (1 or 0, yes or no).
To implement it, you need to start by reading a book on C#. Or you could read through a number of articles on msdn[^].
|
|
|
|
|
Not quite - had you forgotten the ThreeState[^] property?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Oops.
|
|
|
|
|
You might want to change your username. If you use your e-mail address, you'll get spammed.
|
|
|
|
|
In C#, how do you output the contents of a Dictionary class?
Once you have loaded a Dictionary class with keys and values, how do I cycle through them and output the individual values in a foreach loop?
|
|
|
|
|
foreach (KeyValuePair<type1, type2> pair in dict)
{
Console.WriteLine("{0}, {1}",
pair.Key,
pair.Value);
}
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
Try this
Dictionary<object, object> dummyDictionary = new Dictionary<object, object>
{
{"India","Delhi"},
{"USA","WashingtonDC"},
{"Bangaladesh","Dhaka"},
{"Pakistan","Karachi"}
};
foreach (KeyValuePair<object, object> kvp in dummyDictionary)
{
Console.WriteLine(string.Format("Key = {0} Value = {1}", kvp.Key, kvp.Value));
}
var result =
(from kvp in dummyDictionary
select new
{
Key = kvp.Key
,
Value = kvp.Value
});
result.ToList().ForEach(kvp => Console.WriteLine(string.Format("Key = {0} Value = {1}", kvp.Key, kvp.Value)));
Console.ReadKey();
Niladri Biswas
(Code Project MVP 2012)
|
|
|
|