|
I am writing a Windows service in C#, in the constructor for the service I create and two threads to do the work, I then call Start() on both threads in the OnStart event. When I attempt to start the service in the Services manager I get the progress bar for about 30 seconds and then I get a dialog telling me the service did not respond in time (Error 1053).
I have added some debug comments and I can see that the OnStart event handler does return and that the two threads are running. From what I understand the service is up and running when the OnStart handler returns. What would be causing the timeout?
OS is Windows XP SP2, service is .NET 1.1
|
|
|
|
|
It is not completely clear to me from what you are describing, but I guess it is one of these
two:
- your service is not available soon enough, does your initial delay prevent it from
responding to the Services Maneger ? (i.e. did you do say a Thread.Sleep() in the main
thread, instead of using a timer ?)
- or your service exits for some reason (so it starts up OK, but you did not debug till the
end, or for some reason under Services Manager it fails (you are catching all exceptions
and logging them, are you ?)
Hope this helps
|
|
|
|
|
There are a few quirks about creating threads, one of these is that the response to Start (or is it initialise, been a while since I did this) cannot take more than 30 seconds and must return.
It is pretty normal (if not 100% correct or ideal) to start a seperate thread for the initialisation and then return imediatly to the Service Control Manager. This way you avoid the 30 second issue, especially when you need to do things like access a database etc
This way the Service Control Manager gets its desired service started / Initialised in time and leaves you to get on with the work you app needs to do in its own time.
|
|
|
|
|
plz just go through below code:
public class Base
{
public void GetbasePrivate() { }
protected void GetbaseProtected() { }
}
public class child : Base
{
protected void GetchildProtected() { }
public void GetchildPublic() { }
}
static class Program
{
static void Main()
{
Base objbase = new Base();
Base objbase = new Child(); //Please can any one explain these line in details.
}
}
Plz any one can tell me the differences of bold lines. Thx in advance.
Anmol Gupta
|
|
|
|
|
Hi,
new Base() creates an instance of Base, capable of whatever methods/properties are available
in the Base class.
Base objbase = new Base(); sets the variable objbase to refer to that instance, so now
you can do things such as objbase.GetbasePrivate() since that one is public (!)
new Child() creates an instance of Child, capable of whatever methods/properties are available
in the Child class or the Base class, since Child inherits from base.
if you were to do Child child=new Child(); you could now do both child.GetbasePrivate()
and child.GetchildPublic();
Base objbase = new Child(); creates an instance of Child, which automatically also is an
instance of Base since Child inherits from Base, and now the objbase variable refers to it
but acts as if it is a Base instance, forgetting all the extras that may come with
being a Child object too. So now you can do objbase.GetbasePrivate() but you cant
do objbase.GetchildPublic() since the Base class does not have such a method.
This is one of the fundamentals in object-orientation. It is not specific to C#.
If unclear, I strongly suggest you buy a book on C# (or on OO in general) and work
your way through it.
Good luck in the OO world !
|
|
|
|
|
Thanks for your quick response. I agree, what ever you have written there but Just I wanted to know that what is significant of Base objbase = new Child();.
I do not see any differences[Practically] between Base objbase = new Child(); and Base objbase = new Base();
If I am right then why do we use Base objbase = new Child();.
Thanks
Anmol gupta
|
|
|
|
|
Because Child could possibly override and change functionality of it's base class. So it can polymorphically be treated as an instance of the base class but have different behavior. For one thing.
And in the real world, your base class will likely be abstract, meaning you can't create an instance of it directly.
|
|
|
|
|
Hi,
the easiest way to understand its power requires three classes (one parent, two children)
say Control, TextBox, Button
Now you have a Windows Form that contains a lot of Controls, some of them are TextBox,
some are Button, some are whatever...
Form has a collection called Controls that holds all its controls, whatever their
exact type is. You can iterate over that collection like so:
foreach (Control c in myForm.Controls) {
Console.WriteLine(c.Text);
}
So by not relying on specific features, the more general base class works just fine here.
You cannot do foreach (Button btn in myForm.Controls) since now, at run-time it
will encounter a control that is not a Button and the implicit cast will fail.
You cannot do c.PerformClick();
the compiler rejects this because Control does not have that method, Button has.
You can cast explicitly, as in:
Button btn=(Button)c;
And a common pattern is (clicking all the buttons):
foreach (Control c in myForm.Controls) {
Button btn=c as Button;
if (btn!=null) btn.PerformClick();
}
So the advantage is: use a less specialized variable, if you want to generalize your code
(as in c.Text), use the more specialized variable if you need it.
And then there is the whole story about virtual methods and properties...
You really need to read a book you know.
|
|
|
|
|
OK Luc Pattyn Thanks for your suggestion. Can you give me name of some good and comprehensive books which cover Object Oriented concepts with C#.
|
|
|
|
|
Almost any book would do;
my first C# book was "Microsoft Visual C#.NET step by step" by John Sharp and Jon Jagger (2002),
but that is a bit outdated now, since there is C$ 2.0 now, adding features to the language
so you might want to look for a more recent book.
My first OO experience dates way back, cant even remember.
You may find some book recommendations on one of the CP forums.
And you might want to visit the Amazon site, and look at the hundrads of C# books there.
They come with stars and recommendations too.
But then, in my experience book appreciation is a very subjective matter; it all depends
on prior knowledge, personal style, and your attitude towards the balance between
reading, following a classroom course, and doing your own experiments.
|
|
|
|
|
|
As you can see from your example, Child derives from Base. This means that you can create an instance of Child even if you refer to it by an ancestor class. Now, why is this useful? Consider this design (highly contrived, but it does illustrate the point):
public class Sales
{
private double _salesTax = 1.05;
public double CalculateSale(double basePrice)
{
return basePrice * this.SalesTax;
}
public virtual double SalesTax
{
get { return _salesTax; }
}
}
public class EuSales : Sales
{
public override double SalesTax
{
get { return 1.175; }
}
}
public class ShoppingCart
{
private SaleLines _saleLines = new SaleLines();
public SaleLines Lines
{
get { return _saleLines ; }
set { _saleLines = value; }
}
public double TotalSales(Sales tax)
{
return _salesLine.TotalCost * tax.SalesTax;
}
public class SaleLine
{
public string Item;
public double ItemCost;
public int Qty;
}
public class SaleLines
{
private List<SaleLine> _lines = new List<SaleLine>();
public void AddLine(string item, double cost, int qty)
{
SaleLine line = new SaleLine();
line.Item = item;
line.ItemCost = cost;
line.Qty = qty;
_lines.Add(line);
}
public double TotalCost
{
get
{
double runningTotal = 0.0;
for (int i = 0; i < _lines.Count; i++)
{
runningTotal = _lines[i].Qty * _lines[i].ItemCost;
}
return runningTotal;
}
}
}
} Now, if you create a test harness for this and pass in an instance of Sales to the TotalSales method, you will get the a total multiplied by 1.05. If you pass in an instance of EuSales, you get the total multiplied by 1.175%.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi, I am trying to get the username of the user logged into Windows Server 2003 the followiong code seems to work ok for windows xp but when i use the smae code on Server 2003 the code returns a blank.If anyone has any ideas or suggestions they would be appreciated.....
string user = HttpContext.Current.Request.ServerVariables["LOGON_USER"];
Thanks in advance
Tim
|
|
|
|
|
I managed to solve this by turning off anonymous access in iis
|
|
|
|
|
Hi,
Can anybody tell me how to add support for a new languages without ever recompiling the neutral assembly that contains all the application code.After deploying the application I created a satlite assembly for a new language and uploaded to the bin directory of the application.But if I change the application culture it is not reading the values form the new satlite assembly.
Thanks&Regards,
Prajin
|
|
|
|
|
Please don't cross post. It's not good manners.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
hello C# community,
I am trying to add some very simple graphical components to a GUI that I am building in C#, and I wanted to know if there was a way to do this in VS2005 or natively in C#......
I would like to create horizontal/vertical rules, arrows, circles....all that would have no functionality, but simply make the GUI look nicer....Although I could do this in PS or paint and add them as images, I would like to be able to make simple shapes on the fly....
anyone?
I am who I am because of who everyone around me is.
|
|
|
|
|
If you are running on a pre-Vista OS, then you are going to have to learn GDI+ to do this. Basically, you will need to write code that generates these as images and serve them up to the page "on-the-fly".
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
running XP...so, any starting point suggestions of GDI+....
...the more you learn......
I am who I am because of who everyone around me is.
|
|
|
|
|
Suppose that you want to add a simple circle at the corners of your form. One way to do this would be to create a user control and anchor this at each corner. In the control, you would override the Paint method and draw the circle. For instance:
public override void Paint(Graphics g)
{
using (Pen myPen = new Pen(Color.Red, 2))
{
g.DrawEllipse(myPen, this.Bounds);
}
}
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
wicked...this is more or less what I was looking to do...I'm sure if I mess around with it for a little....
thank you...
I am who I am because of who everyone around me is.
|
|
|
|
|
No problem - glad to help.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Graphics.FromHandle(...);
If you pass the handle of a control (panel eg) you can use the received object to draw on that control.
Most methods in the Graphics Object speak for themself (and there is always MSDN)
hope this helps.
V.
If I don't see you in this world, I'll see you in the next one... And don't be late. (Jimi Hendrix)
|
|
|
|
|
thanks V,
MSDN is where I'll head over to check out the Graphics object....I'm new to C# so any tips are always appreciated.
thx
I am who I am because of who everyone around me is.
|
|
|
|
|
Does anyone know of a C#/.NET telnet component that supports ibm 3151 terminal emulation?
Don't be overcome by evil, but overcome evil with good
|
|
|
|