|
My manners are irrelevant. I do not like to spoon-feed people.
|
|
|
|
|
leppie wrote: My manners are irrelevant.
Well said, Seven!
|
|
|
|
|
|
livez wrote: work on your manners a bit
His responses appeared to be quite polite. Curt, for sure, but polite.
|
|
|
|
|
Yes you´re quite right. My apologies Leppie.
|
|
|
|
|
in general these kinds of casts will only work towards the base class. ie a test is an XmlDocument but an XmlDocument is Not necessarily a test.
you could use the "as" operator
t = doc as test;
this will return t == null if doc is not of type test.
If you know how to convert an XmlDocument into a test then you could create a cast for it
public static explicit operator Test(XmlDocument doc)
{
//your conversion algorithm here
}
HTH
Russ
|
|
|
|
|
I have created a windows service to send email on daily basis. It has a timer object that fires an event after 24 hours,
private System.Timers.Timer timer = new System.Timers.Timer (86400000);
In timer event I do my working i.e. I send my emails, something like this:
private void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
{
eventLog1.WriteEntry("Calling web service for Sending Reminders on " + DateTime.Now.ToLongDateString());
if (EmailObj.SendReminder())
{
eventLog1.WriteEntry("The operation was successfully completed on " + DateTime.Now.ToLongDateString());;
}
else
{
eventLog1.WriteEntry("There was some error, the operation failed on " + DateTime.Now.ToLongDateString());;
}
if (DateTime.Today.Day == 1)
{
}
}
The problem is, I have installed the service on Windows server 2003, but the service starts and stops immediately with the message
“The MyServiceName service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service”
I can see the event log entries that I did on OnStart event of the service; also the service is working fine on Windows XP.
Please help me I have to run this service on MS Windows server 2003 forever to send emails on daily basis,
cout << "\0";
// its backSlashZero
|
|
|
|
|
What is there in your OnStart() method ? Is your timer enabled ?
backSlashZero wrote: private System.Timers.Timer timer = new System.Timers.Timer (86400000);
You are keeping the thread sleeping for such a long time. Better method to do this is to write a console application which sends mail and exits automatically. Use windows scheduler to schedule this exe to run at required time. So you are not keeping any threads sleeping for long time. Windows service should be used, if it has to do processing all time when it runs, not for scheduling like this, AFAIK.
|
|
|
|
|
N a v a n e e t h wrote: Better method to do this is to write a console application which sends mail and exits automatically. Use windows scheduler to schedule this exe to run at required time.
Thanks I am going to do this now
cout << "\0";
// its backSlashZero
|
|
|
|
|
Add a keep-alive thread that doesn't do anything but sleeps for 4.5 seconds.
protected void KeepAliveThread()
{
ServiceController controller = new ServiceController(this.ServiceName);
while (true)
{
if (controller.Status == ServiceControllerStatus.Running)
{
Thread.Sleep(4500);
}
}
}
In your OnStart() method, do this:
Thread thread = new Thread(new ThreadStart(KeepAliveThread));
thread.Start();
"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! I tried it out but problem is still there
cout << "\0";
// its backSlashZero
|
|
|
|
|
Are you doing the following in OnStart()?
timer.Enabled = true;
timer.Start();
"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
|
|
|
|
|
Yes i did!
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("In OnStart: Calling web service for Sending Reminders on "
+ DateTime.Now.ToLongDateString());
EmailObj.SendReminder(); \\send reminders if any!
timer.Enabled = true;
timer.Start();
}
cout << "\0";
// its backSlashZero
|
|
|
|
|
DropDownList ddlst = new DropDownList();
ddlst = (DropDownList)e.Item.Cells[1].FindControl("eddpgmtype");
Object cobj = new Object();
objArrEntity = cobj.type_bind();
ddlst.DataSource = objArrEntity;
ddlst.DataTextField = "type";
ddlst.DataValueField = "ID";
ddlst.DataBind();
ddlst.SelectedItem.Text = e.Item.Cells[11].Text.ToString();
in cells[11] i have a hidden column of "type"
this is my code for binding data to dropdown when edit command is clicked.
actually dropdown consists of inbound,outbound,backoffice
the first record consits of programtype 'outbound' in datagrid
when i click edit i should able to see this outbound in dropdownlist as first item as well as list items of main dropdown(inbound,outbound,backoffice).but this inbound is getting overwritten by outbound.
i think question is clear
plz help me in binding the data as mentioned above.
Thank u
|
|
|
|
|
Hello everyone,
Here is my simple application code for a Windows Service application. The question is, when stop the service, there is always,
// [System.InvalidOperationException] = {"Please call the Start() method before calling this method."}
Does anyone have any ideas why there is such issue and how to fix?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Net;
using System.Threading;
namespace TestServiceStop1
{
public partial class Service1 : ServiceBase
{
private Thread _tHttpThread;
private TestHttpServer _server;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
_server = new TestHttpServer(this);
_tHttpThread = new Thread(_server.StartListen);
_tHttpThread.Start();
}
protected override void OnStop()
{
_server.Stop(false);
}
}
public class TestHttpServer
{
private int _Port = 0;
private HttpListener _Server = new HttpListener();
private Service1 _manager;
public TestHttpServer (Service1 manager)
{
_manager = manager;
}
public int ListenPort
{
get
{
return _Port;
}
set
{
_Port = value;
}
}
public void StartListen()
{
try
{
IAsyncResult result;
_Server.Prefixes.Add(String.Format("http://+:{0}/", 9099));
_Server.Start();
while (true)
{
result = _Server.BeginGetContext(new AsyncCallback(this.HttpCallback), _Server);
result.AsyncWaitHandle.WaitOne();
}
}
catch (Exception ex)
{
throw ex;
}
}
public void Stop(bool isTerminate)
{
_Server.Stop();
}
private void HttpCallback(IAsyncResult result)
{
HttpListenerContext context = _Server.EndGetContext(result);
HandleRequest(context);
}
private void HandleRequest(HttpListenerContext context)
{
string matchUrl = context.Request.Url.AbsolutePath.Trim().ToLower();
context.Response.StatusCode = 200;
context.Response.StatusDescription = "OK";
context.Response.Close();
}
}
}
thanks in advance,
George
|
|
|
|
|
George_George wrote: _Server.Stop();
I can't find where you are stopping the thread. You are just stopping the HTTPListener, not the thread. OnStop() method should be able to exit the thread also, I guess. Not sure this will be the reason for error.
|
|
|
|
|
Sorry N a v a n e e t h,
My English is not very good. You mean I need to stop the thread tHttpThread in OnStop?
regards,
George
|
|
|
|
|
George_George wrote: You mean I need to stop the thread tHttpThread in OnStop?
Yes. The thread is not stopping in your code. Stop that on OnStop() method.
|
|
|
|
|
Thanks N a v a n e e t h,
How to stop the thread gracefully? I think of using Abort, but we have discussed before this method call is not a good idea always.
regards,
George
|
|
|
|
|
Go with this[^]. It will work.
|
|
|
|
|
Actually because the BeginGetContext call will throw an exception when the _Server object is stopped, the thread will stop too so no extra work is actually required.
|
|
|
|
|
I mean the thread which he created.
|
|
|
|
|
I know which thread you mean.
The thread he creates uses the StartListening Function. In that function the BeginGetContext call is made, and this will throw the InvalidOperationException when the _Server object is stopped. So the thread he creates really does exit when the _Server stops. He will just need to catch the InvalidOperationException and evaluate that it is expected behaviour.
|
|
|
|
|
Thanks GDavy!
If I fixed in this way, are there any need to stop the tHttpThread thread?
while (true)
{
if (_Server.IsListening)
{
result = _Server.BeginGetContext(new AsyncCallback(this.HttpCallback), _server);
result.AsyncWaitHandle.WaitOne();
}
else
{
break;
}
}
regards,
George
|
|
|
|
|
GDavy wrote: In that function the BeginGetContext call is made, and this will throw the InvalidOperationException when the _Server object is stopped. So the thread he creates really does exit when the _Server stops. He will just need to catch the InvalidOperationException
I know. I was suggesting him to stop that thread when HTTPListener stops, so it won't call again BeginGetContext() . Will that be a good method than catching exception, and thread getting aborted automatically ?
|
|
|
|