|
|
Hi
How can we check the failure of windows service programatically. I have a windows service that elapses every 5 minutes and I need to check if the service is failed then restart it automatically in my code. I googled but I couldnt find the Failed Status for the windows service.
Any ideas please!
|
|
|
|
|
I take failure as your service breaks ie exception. Correct me if I am wrong. If this is the case, then you need to rethink. An application that breaks every 5 minutes is not desirable.
जय हिंद
|
|
|
|
|
The ServiceController[^] allows you to Start, Stop and check the running status of services.
|
|
|
|
|
But that will work only if the service does not "fails". Isn't it?
जय हिंद
|
|
|
|
|
That depends on what "fails" means. I took it to mean "crashes" in which case this will allow the OP to restart the service. If it means something else then no, this probably isn't very helpful.
|
|
|
|
|
I took it to mean "exception" and I guess "crashes" is referring to that only. That is why I asked, will this works even if the service encounters an exception(crash).
जय हिंद
|
|
|
|
|
Lets say I'm using the vs2008 convention of setting up properties and have a Base class and inherited classes. Is there a way in my base class that I can attach event handler to properties the child and base may have to determine if the set method of a property get used. Looking for something to add to base class that would setup the notification.
eg
static enum State (isUnchanged,isNew,isModified,isDeleted)
class MyBase
{
public State myState;
}
class MyChild : MyBase
{
public string FirstName {get;set;}
public string LastName {get;set;}
}
|
|
|
|
|
You can do something like this but you'll have to set the state in the setter for each property.
class MyBase
{
public event EventHandler StateChanged;
private State state;
public State State
{
get { return state; }
set
{
if (state != value)
{
state = value;
OnStateChanged(EventArgs.Empty);
}
}
}
protected virtual void OnStateChanged(EventArgs e)
{
EventHandler eh = StateChanged;
if (eh != null)
eh(this, e);
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Not quite where I was heading,
My baseclass will have no idea what properties the child class has so in pseduo code I'm wondering if something like this is possible
The idea is to have a means of setting
BaseClass
protected void SetupHandlers()
foreach property in MyProperties
AttachSetChangeEvent ()
public BaseClass()
{
SetupHandlers();
}
|
|
|
|
|
I don't think it's possible. Maybe one of the other guys knows a way - if there is one it could be very interesting.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Not without a lot of work, I'm afraid.
With a class like
class NotifiableProperty<T>
{
T val;
public event Action PropertyChanged;
public T Value
{
get { return val; }
set { val = value; PropertyChanged(); }
}
public static implicit operator T(NotifiableProperty<T> p)
{
return p.Value;
}
}
you can do
class MyClass
{
NotifiableProperty<int> p = new NotifiableProperty<int>();
public MyClass()
{
p.PropertyChanged += new Action(() => Console.WriteLine("Changed"));
}
public int P
{
get { return p; }
set { p.Value = value; }
}
}
and then when you do
MyClass m = new MyClass();
m.P = 20;
you will see "Changed" printed on the screen.
I don't know how to automatically hook to the events, and I don't think setting up events from the base class is a good idea, as there is the possibility that derived class members wouldn't have been initialized at that point. Maybe use reflection inside the derived class?
|
|
|
|
|
I think another way to phrase this question is
How about a way to override the set; method for a property
In VS2008 you don't need to specify a private field for properties and can just use
public int myprop {get;set;}
So if I could figure out how to override that set method, maybe thats where I could add change event handler.
|
|
|
|
|
I want to print a multipage tiff image. I want first to get a print preview but when I want to get more pages to the printdocument I only get the last page of the image.
Can anyone help me to solve this problem?
code:
Image image = Image.FromFile(@strBestandsPad);
AfbeeldingFormaat abf = new AfbeeldingFormaat();
Point puntPagina = new Point(0, 0);
int intPaginas = image.GetFrameCount(FrameDimension.Page);
int i = 0;
if (intPaginas > 1)
{
while(i < intPaginas)
{
e.HasMorePages = true;
Rectangle rec = new Rectangle(0, 0, 763, 1084);
image.SelectActiveFrame(FrameDimension.Page, i);
Image newImage = image;
newImage = abf.FixedSize(nieuwImage, 763, 1084); // set image to A4 page size
e.Graphics.DrawImage(nieuwImage, rec);
i++;
}
}
else
{
e.HasMorePages = false;
}
thanks,
|
|
|
|
|
Did you ever get this answered? I am looking for this solution now.
Peace.
|
|
|
|
|
No, but I've the answer.
With this metho I size the image to the wright size. You can put this method in a seperate class.
<br />
public Image FixedSize(Image imgPhoto, int Width, int Height)<br />
{<br />
int sourceWidth = imgPhoto.Width;<br />
int sourceHeight = imgPhoto.Height;<br />
int sourceX = 0;<br />
int sourceY = 0;<br />
int destX = 0;<br />
int destY = 0;<br />
<br />
float nPercent = 0;<br />
float nPercentW = 0;<br />
float nPercentH = 0;<br />
<br />
nPercentW = ((float)Width / (float)sourceWidth);<br />
nPercentH = ((float)Height / (float)sourceHeight);<br />
<br />
<br />
if (nPercentH < nPercentW)<br />
{<br />
nPercent = nPercentH;<br />
destX = (int)((Width - (sourceWidth * nPercent)) / 2);<br />
}<br />
else<br />
{<br />
nPercent = nPercentW;<br />
destY = (int)((Height - (sourceHeight * nPercent)) / 2);<br />
}<br />
<br />
int destWidth = (int)(sourceWidth * nPercent);<br />
int destHeight = (int)(sourceHeight * nPercent);<br />
<br />
Bitmap bmPhoto = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);<br />
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);<br />
<br />
Graphics grPhoto = Graphics.FromImage(bmPhoto);<br />
grPhoto.Clear(Color.White);<br />
grPhoto.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;<br />
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;<br />
grPhoto.SmoothingMode = SmoothingMode.AntiAlias;<br />
grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality;<br />
grPhoto.CompositingQuality = CompositingQuality.HighQuality;<br />
<br />
grPhoto.DrawImage(imgPhoto,<br />
new Rectangle(destX, destY, destWidth, destHeight),<br />
new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),<br />
GraphicsUnit.Pixel);<br />
<br />
grPhoto.Dispose();<br />
return bmPhoto;<br />
}
The next thing I did was to create class that derive from printdocument.
The next part of code:
public class PrintImage : PrintDocument<br />
{<br />
private int currentPage;<br />
<br />
private int numberOfPages;<br />
<br />
private Image imageToPrint;<br />
<br />
public Image ImageToPrint<br />
{<br />
get<br />
{<br />
return this.imageToPrint;<br />
}<br />
<br />
set<br />
{<br />
this.imageToPrint = value;<br />
this.numberOfPages = this.imageToPrint.GetFrameCount(FrameDimension.Page);<br />
}<br />
}<br />
<br />
protected override void OnBeginPrint(PrintEventArgs e)<br />
{<br />
base.OnBeginPrint(e);<br />
<br />
this.currentPage = 0;<br />
<br />
if (this.imageToPrint == null)<br />
{<br />
throw new ArgumentNullException("ImageToPrint");<br />
}<br />
}<br />
<br />
protected override void OnPrintPage(PrintPageEventArgs e)<br />
{<br />
AfbeeldingFormaat afb = new AfbeeldingFormaat();;<br />
base.OnPrintPage(e);<br />
<br />
this.ImageToPrint.SelectActiveFrame(FrameDimension.Page, this.currentPage);<br />
<br />
using (var bmp = new Bitmap(this.imageToPrint))<br />
{<br />
Image image;<br />
<br />
image = afb.FixedSize(bmp, e.PageBounds.Width, e.PageBounds.Height);<br />
<br />
e.Graphics.DrawImage(image, e.PageBounds);<br />
<br />
e.HasMorePages = ++this.currentPage < this.numberOfPages;<br />
}<br />
}<br />
}
And then the last part to print.
<br />
PrintDocument printDocument = new PrintImage { ImageToPrint = Image.FromFile(path) };<br />
<br />
var ppd = new PrintDialog<br />
{<br />
Document = printDocument<br />
};<br />
<br />
if (ppd.ShowDialog() == DialogResult.OK)<br />
{<br />
<br />
printDocument.Print();<br />
<br />
}<br />
<br />
I hope this helps you.
|
|
|
|
|
A bit TMI, but your code does contain the answer, which is here (after selecting the active frame on the image, simply create a new bitmap from it and use that bitmap to print to the graphics object):
protected override void OnPrintPage(PrintPageEventArgs e)
{
base.OnPrintPage(e);
this.ImageToPrint.SelectActiveFrame(FrameDimension.Page, this.currentPage);
using (var bmp = new Bitmap(this.imageToPrint))
{
e.Graphics.DrawImage(bmp, e.PageBounds);
e.HasMorePages = ++this.currentPage < this.numberOfPages;
}
}
|
|
|
|
|
Hi,
How save a picture from a WebCam Stream to .bmp
The camera has a fixed resulution of 2MP.
I want to write it in C#.
thanks
|
|
|
|
|
Safe from what, the rain? just give it an umbrella
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
You'll have to consult the documentation on the library you're using to get the video from the webcam.
|
|
|
|
|
Which documentation? I don't know how to start, which library should I take?
|
|
|
|
|
Contact the manufacturer of the webcam to see if they put out a SDK (Software Development Kit) that you can use. It should come with the libraries and the documentation on how to use them.
|
|
|
|
|
hello all can any body help me to convert class to dll file
|
|
|
|
|
Set project output type to Class Library
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|