|
Right - that's fairly straighforward then. OK, how I would structure this (very loosely):
I would have a manager class which was responsible for triggering the different timed events. This class would also be responsible for triggering the insert/lookup into the database of the system identifier (if I was doing this, I would put this in a separate data layer which could easily be mocked for testing purposes, and I would have the data access happen on a background thread in order not to slow down the startup of the service too much).
I would keep the identifier as a property in the manager class. Now, the manager class would be a member of the service class, and I would instaniate it in the OnStartup event (triggering the system identification).
I hope that this gives you some ideas.
|
|
|
|
|
Pete, I'm sorry but you have lost me, I am insufficiently advanced to fully understand what you are suggesting.
Are you suggesting that I created a second .cs or that I create classes in the same namespace? e.g.
using this;
using that;
namespace a
{
class MyService
{
public MyService()
{
InitializeComponent();
//do stuff
}
}
class Manager
{
public class Manager()
{
// do the get/set id thing
}
}
class ServiceStart
{
protected override void OnStart(string[]args)
{
// create event logs and EnableRaisingEvents stuff
}
}
}
If you would like me to I'll happily post the code I have adapted.
|
|
|
|
|
Not quite. I would create a second class - this does nothing with regards to service management, and it would look something like this:
public class TimedEventManager
{
private BackgroundWorker bw = new BackgroundWorker();
public void Initialise()
{
bw.DoWork += CheckForId();
bw.RunWorkerAsync(null);
}
private void CheckForId(object sender, DoWorkEventArgs e)
{
bw.DoWork -= CheckForId();
bw.Dispose();
}
public int Id { get; set; }
} Then, in your service class, I would create an instance of this:
private TimedEventManager timedEvent;
protected override OnStart(string[] args)
{
timedEvent = new TimedEventManager();
timedEvent.Initialise();
} And that's it. That's how you hook it together.
|
|
|
|
|
Hiya Pete & thank you for helping me out, it is appreciated.
Sorry if I am being thick but I still can't get the SysID to carry across so that I can use it repetitively.
I would like to post my code so that you could look at it and tell me what I am doing wrong but there is a LOT of it and popping it in a forum message makes it hard to read.
Suggestions?
|
|
|
|
|
Put it somewhere that I can download it from and I may be able to take a look at it - no promises at the moment.
|
|
|
|
|
I'll try and do it tonight or, failing that, tomorrow morning-ish. Thanks Pete.
|
|
|
|
|
No problem, but just be aware that I tend not to spend much time on CP at weekends as I like to spend time with the family, and I don't have email notifications turned on because my inbox used to get overwhelmed by emails.
|
|
|
|
|
I agree, wives and kids are a lot more fun (well, after the Saturday morning grocery shopping is done). I'll put the timed_events stuff in as well so you will be able to get a better picture of what it is I am trying to do.
Have a great Friday.
M.
|
|
|
|
|
|
My apologies, I've been insanely busy for the last couple of days. If you'd care to reupload your code, I have temporarily enabled the option to email me, so you can send me the location of it and I will download it later on.
|
|
|
|
|
Hi Pete,
Please don't apologise, it is you who is doing me a favour...
I've put the code here http://pastebin.com/ye3N3NNY[^]
I have more-or-less got it working. The problem I am having is the line "private static void OnTimedEvent(object source, ElapsedEventArgs e)". If I leave it as is the various methods run and populate the database but I can't use the SID (System ID value) value previously created with a get/set.
To access the SID I have to change it to a "public" method but then the db doesn't get populated...
Thanks once again for looking at my (hopefully not to shabby) code.
M.
|
|
|
|
|
You can't use SID because it's an instance variable, but the static method indicates you need to use static variables, so you either need to convert your property and field to static
private static int SID;
public static int mID or you remove the static from the OnTimedEvent.
|
|
|
|
|
aaaarghhh....of course!!!
|
|
|
|
|
Fresh pair of eyes and all that.
|
|
|
|
|
Could you please stop using the phrase "Greetings Gurus"? You don't need to use it to get help - just keep asking decent questions and provide us with enough information to help. By using this phrase, you're coming across as a crawler - and that's a bit offputting.
|
|
|
|
|
Hi Pete,
My apologies if you found the greeting distasteful, it was meant to be cheerful and recogniscent of the superior abilities held by some of those in the forum .
I shall refrain in the future.
Thanks for pointing it out.
|
|
|
|
|
CCodeNewbie wrote: recogniscent of the superior abilities
That implies an elitism that doesn't exist. We may have more experience in some areas, but this does not infer any form of superior ability. Each of us has deficiencies in our knowledge that others cover for - for instance, I tend not to answer much on the p/invoke side because it's not an area I deal much with.
[Edit]Don't get me wrong - you ask good questions. You provide detail and clarification, along with actual code. That means we are more than happy to help, so just keep this part up and we'll all be happy.
|
|
|
|
|
Will do
|
|
|
|
|
Hello Experts,
I would like to ask even though I manage to add the Merge Module for visual studio 2010 so that I can deploy my Application that uses crystal report I still got the error below.
Could not load file or assembly CrystalDecisions.Windows.Forms.Version=13.0.2000.0
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.IO.FileNotFoundException: Could not load file or assembly 'CrystalDecisions.Windows.Forms, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified.
File name: 'CrystalDecisions.Windows.Forms, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304'
at SimplyOutbound.Form1.InitializeComponent()
at SimplyOutbound.Form1..ctor()
at SimplyOutbound.ReportGenerator.btnView_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Any advice, suggestion are so much appreciated.
Thanks,
DAN
|
|
|
|
|
Hello,
I was a bit lucky I manage to fix it also. I am not sure but might be helpful to others also, it seems the error can be done by the previous version of crystal report that is being installed in the client machine. I tried to properly uninstall the previous version of the crystal report then repeat the same I process until its successful.
|
|
|
|
|
|
I'm a relatively new C# programmer and am using datagridview to maintain my data. However, some of the tab pages in my application need to show data and data subsets in a different format. Some of it will be row-based instead of column-based. Here's an example; if I have 4 objects, each taking up one row of a datagrid in the first tab I will need to break that up into 4 columns per object in another tab for a total of 16 columns and another tab will break that into 4 groups of 6 rows for a total of 24 rows. I also might want to get rid of the grid "look" and show it in more of a row-based/column based reporting format that will still be bound to a set of underlying methods. Before I start trying to do this with datagridview (perhaps it's not even possible) does anyone out there have any better ideas as to how to go about this? The key is that the data has to be bound to underlying calculations, kind of like a spreadsheet, but I need a lot of flexibility as to how I go about it. Thanks in advance.
|
|
|
|
|
On a tangent:
Tom Paronis wrote: need to show data
Don't show data; show information.
Tom Paronis wrote: am using datagridview
|
|
|
|
|
I'm using VS2008 with C# and SQL CF v3.5 to create an inventory application for a mobile computer. I have never worked with SQL Compact before, but I'm pretty sure I've got it right from the database perspective. I've added my DataSource, TableAdapters, queries to fill my ComboBoxes, etc. When I deploy to my WM 6.5 device, I've made sure that the SQL Compact CAB files have been installed, and that the database exists on the device. When I use any of the ComboBoxes in the form, they are all blank and none of them are populated. In VS 2008 when I 'Preview Data' it's all there. Not sure where to go from here to debug?
|
|
|
|
|
I’m writing one program (C# .Net 3.5) for temperature values reception from some device through COM port. The program (for convenient postprocessing of temperature values) divides received data on (figure 1):
MEASURE – continuous sequence of temperature values.
SET – consecutive set of several MEASUREs. Each SET is separated from another SET by a certain interval of time. For example, 15 minutes. After this time limit the program closes current SET and opens a new SET.
DAY – set of SETs received during a day.
The program seems to work as it supposed. But sometimes there is an overlapping of MEASUREs of different SETs of a DAY. For example, a MEASURE of one SET could be an absolute copy of a MEASURE of some another following SET (figure 2). Or any SET besides of its own MEASUREs can contain all MEASUREs of all following SETs. As a result some SET has MEASURE(s) which do not belong to it.
I have an idea that List M (see the code) of a SET sometimes during a day can refer on itself and on List M of the previous SET. It is incredible, because only one (current) SET and its (current) MEASURE could be active; the rest should be closed and not active.
What is wrong? What recommendations you will advise to reveal this bug?
figure 1
figure 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
namespace WindowsFormsApplication1
{
class MyPoint
{
public double x;
public double y;
}
class Measurement
{
List<MyPoint> points = new List<MyPoint>();
public void Add(MyPoint p)
{
points.Add(p);
}
}
class Set
{
public Measurement CurrentM = null;
List<Measurement> M = new List<Measurement>();
public Measurement GetNewM()
{
Measurement m = new Measurement();
return m;
}
public void CreateMesurement()
{
CurrentM = GetNewM();
M.Add(CurrentM);
}
}
class Day
{
public Set CurrentS = null;
List<Set> S = new List<Set>();
public void OnSetCreation()
{
CurrentS = new Set();
S.Add(CurrentS);
}
public void OnMeasureCreation()
{
CurrentS.CreateMesurement();
}
public void WriteData()
{
}
}
static class DaysConteiner
{
static public Day Active;
static double Temperature;
static bool IfThereIsAGapBetweenTempuratureValues = false;
static bool IfThereIsSetTimeLimitElapsed = false;
static bool IfNewDay = false;
static void OnStartNewDay()
{
if (IfNewDay)
{
Active.WriteData();
Active = new Day();
}
}
static internal void OnDataFromCOMPortReceived()
{
if (IfThereIsSetTimeLimitElapsed) Active.OnSetCreation();
if (IfThereIsAGapBetweenTempuratureValues) Active.OnMeasureCreation();
MyPoint p = new MyPoint();
p.x = DateTime.Now.ToOADate();
p.y = Temperature;
Active.CurrentS.CurrentM.Add(p);
}
}
}
|
|
|
|