|
Greetings Gurus,
I need an event to fire at set times during the day from a Windows service.
Code so far
protected override void OnStart(string[] args)
{
if (DateTime.Now.TimeOfDay == System.TimeSpan.Parse("09:00:00"))
do something
but I would like it to run at 13:00, 17:00 & 21:00 too.
What is the correct syntax please as I can't find any examples of how to do this. I don't want it to run every 4 hours (e.g. 01:00, 05:00) so I would prefer not to use a static schedule.
I would also like to add an event log entry if the service didn't run at the scheduled time so that it could be investigated but am not sure about how to go about it.
Could you help please?
|
|
|
|
|
I've done a similar process in the past by setting up tasks on a background thread that get run at the appropriate time. These threads are then put to sleep until the appropriate point, when they wake themselves up and perform their task. Upon completion, the thread is put back to sleep until the same time the following day. The beauty about this approach is that the only loop you need to put in place is the one that kicks it off in the first place, and closing down the service should just involve shutting down the sleeping threads.
When I wrote this, I used a Mutex and based the sleep interval on a TimeSpan .
|
|
|
|
|
CCodeNewbie wrote: if (DateTime.Now.TimeOfDay == System.TimeSpan.Parse("09:00:00"))
Don't use equality tests on (almost) continuous types, such as DateTime, float, double. Two independent values will hardly ever be equal, DateTime may have a resolution of 1 Tick, i.e. a tenth of a micro-second. Either use a simple greater-equal test, or perform an interval test.
|
|
|
|
|
What I have done in the past is to have a Windows Service cycle every second or ten that scans a database table for tasks that are due and runs them.
CCodeNewbie wrote: I would also like to add an event log entry if the service didn't run at the
scheduled time so that it could be investigated but am not sure about how to go about it.
That's just silly. Why log something when it could run the task instead?
|
|
|
|
|
Hi, I have a panel and custom controls on it. I know how to select multiple controls by clicking on an empty space on the panel and move the mouse but how can I do it if the panel is covered fully by controls and not visible?
All I want is to click on any of the controls and drag the mouse on the other controls to select them. Any clue would be appreciated.Thanks
|
|
|
|
|
Does Ctrl+Mouse-click work?
0100000101101110011001000111001011101001
|
|
|
|
|
Thanks I did Ctrl+click, it works but I also want my users to select the controls with only one hand
|
|
|
|
|
In that case you really need free space to start your mouse drag.
0100000101101110011001000111001011101001
|
|
|
|
|
Thanks, at least I won't spend my time for a thing which is not possible.
|
|
|
|
|
teknolog123 wrote: I did Ctrl+click, it works but I also want my users to select the controls with only one hand Just curious: I assume you are speaking here of "your users" as "design-time" consumers within Visual Studio ... where they have your Panel's source code within their own projects, and can manipulate any object inside the Panel, delete it, move it, etc., ... ? And the controls within your Panel (via use of Dock and Anchor) completely fill the Panel ... so if the user did resize it no Panel surface would be exposed ?
best, Bill
"Use the word 'cybernetics,' Norbert, because nobody knows what it means. This will always put you at an advantage in arguments." Claude Shannon (Information Theory scientist): letter to Norbert Weiner of M.I.T., circa 1940
|
|
|
|
|
BillWoodruff wrote: Just curious: I assume you are speaking here of "your users" as "design-time" consumers
No, I mean runtime users
|
|
|
|
|
teknolog123 wrote: No, I mean runtime users Hi, Now that it's clear this is a run-time scenario: curious to know if your goal is to have a visible selection rectangle appear, and for controls to visually indicate their selected state.
Have you considered an alternative selection mechanism, such as a pop-up window that has TreeView with CheckBoxes where the Control hierarchy can be represented ... perhaps selected from a custom context menu ... that could possibly still enable you to stay in 'one-handed' mode ?
Have you written your selection code already ? Are you still interested in pursuing this ?
best, Bill
"Use the word 'cybernetics,' Norbert, because nobody knows what it means. This will always put you at an advantage in arguments." Claude Shannon (Information Theory scientist): letter to Norbert Weiner of M.I.T., circa 1940
|
|
|
|
|
BillWoodruff wrote: Have you written your selection code already ?
Yes I did but not the way I wanted.
What I wanted was to click on a control and move the mouse to the others (with the help of a visible selection rectangle) to select the controls which intersect with the selection rectangle
What I did : I click the panel that contains all those controls (with a selection rec. visible only on the panel not the controls) and move the mouse.Intersection with rectangle logic is same
the point is I don't want to enlarge the panel to leave a clicking space for selection.The panel should be invisible behind the controls
|
|
|
|
|
Hi Guys,
I want to add few files to already running application, with out Building application is this possible with any framework..Please let me know...
|
|
|
|
|
As far as I know, its not.
Too much of heaven can bring you underground
Heaven can always turn around
Too much of heaven, our life is all hell bound
Heaven, the kill that makes no sound
|
|
|
|
|
pravin_mun wrote: few files
what is in those files? are they executable (EXE, DLL), source files (C#), or something else?
You can load DLLs dynamically, call native code using P//Invoke and managed code using reflection.
You can compile C# files at run-time, the necessary tools are part of the .NET framework.
|
|
|
|
|
It could load plug-ins if you tell it how.
|
|
|
|
|
Hi guys, i want to create userdefined controls in different ascx (1.ascx, 2.ascx, 3.ascx)files at runtime in some button click.. Can some one please let me know the process of doing the same..
|
|
|
|
|
|
Hi
I am invoking a simple web service from Windows form to do simple addition.
The client code is as follows, defined array of int and setting values based on number pressed in the form.
Want to pass the array as parm to web service. Getting error that the method in web service does not have compatible arguments. Can you pls help to see find the issue is.
Client Code
namespace Calculator
{
public partial class Form1 : Form
{
private int sumSoFar;
private int[] numcalc = new int[10];
public Form1()
{
InitializeComponent();
sumSoFar = 0;
for (int i = 0; i < 10; i++)
{
numcalc[i] = 0;
}
}
private void button0_Click(object sender, EventArgs e)
{
numcalc[0] = 0;
}
private void button1_Click(object sender, EventArgs e)
{
numcalc[1] = 1;
}
private void button2_Click(object sender, EventArgs e)
{
numcalc[2] = 2;
}
private void button3_Click(object sender, EventArgs e)
{
numcalc[3] = 3;
}
private void button4_Click(object sender, EventArgs e)
{
numcalc[4] = 4;
}
private void button5_Click(object sender, EventArgs e)
{
numcalc[5] = 5;
}
private void button6_Click(object sender, EventArgs e)
{
numcalc[6] = 6;
}
private void button7_Click(object sender, EventArgs e)
{
numcalc[7] = 7;
}
private void button8_Click(object sender, EventArgs e)
{
numcalc[8] = 8;
}
private void button9_Click(object sender, EventArgs e)
{
numcalc[9] = 9;
}
private void button13_Click(object sender, EventArgs e)
{
MathOps.Service1SoapClient MathOpsObj = new MathOps.Service1SoapClient() ;
sumSoFar = MathOpsObj.AddValues(numcalc);
<< err in this line, I thought numcalc is an array that can be passed as argument to web service, somehow getting error>>
}
}
}
Web service code
namespace MathOps
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public int AddValues(int [] num)
{
int sumSoFar = 0;
for (int i = 0; i < 10; i++)
{
sumSoFar = sumSoFar + num[i];
}
return sumSoFar;
}
}
}
|
|
|
|
|
What is the exact error message you are getting?
I am guessing you to get an error mentioning
cannot convert from 'int[]' to 'MathOps.ArrayOfInt'
If this is the case try the following
MathOps.ArrayOfInt myClientArray = (MathOps.ArrayOfInt)numcalc;
sumSoFar = MathOpsObj.AddValues(myClientArray);
0100000101101110011001000111001011101001
modified 8-Oct-11 20:08pm.
|
|
|
|
|
Hi Andre
Thanks much for the reply. Sorry for the delay in my response. Had to go out of town. I googled the issue and found the same solution as you have suggested and it works like a charm.
Thanks very much.
|
|
|
|
|
There is any Merge Modules for Crystal Report 2008
|
|
|
|
|
Yes[^]?
Bastard Programmer from Hell
|
|
|
|
|
Eddy Vluggen wrote: Yes?
I've never seen a nullable yes before.
|
|
|
|