|
could work?...hmmm the reson why I am using threads is that I have multiple event types....
each event type has a start and end event and the 10 min time out is different..hence I allocated different thread with timeouts.
Thanks
Daphne
|
|
|
|
|
I would like to request some suggestions on a problem I am having with a Windows Service I built.
It installs and runs fine, using a timer every minute to check for files, then running a process.
I have the process logging to a Windows Event Log, also, every time if does find and process a file it writes a record to a remote SQL server with file stats.
The third thing the service does is send out e-mails.
One type is a daily summary with totals and stats
The second is whenever an error is caught, it collects the error data and sends it to a support group (Also writes to the event log)
I also e-mail, write SQL & log at service Start and Stop.
The issue is that the logging works OK at Stop if I do it from the Services panel in Admin Tools. However, if the Box is re-started by doing a Start/Shutdown/Re-start, I get no logging or e-mails to notify that the box is going down. I do get the Start up messages and logging minutes later when the system restarts.
However, if someone were to do a Start/Shutdown/Shutdown, I would not be notified and it might be several hours before other processes noticed that the data stream had stopped and complain about it.
Here is the code from my OnStop section:
protected override void OnStop()<br />
{<br />
closeResources("ALL",9);<br />
<br />
eventLogOSNUCAS.WriteEntry("OSNUCAS Reader is shutting down",EventLogEntryType.Error);<br />
<br />
writeDashboardLogLine("OMAH799", "###########", 0, "OSNUCAS Reader is shutting down", 0, 0, 0, 0, "Stopped", "##########NUCASReader on " + Environment.MachineName + " has shut down");<br />
<br />
AutoEMailSender("########## NUCAS Reader is shutting down", "########### NUCAS Reader service is shutting down\n", 1);<br />
<br />
<br />
}
What do I have to do to ensure that a shutdown event is logged?
(Obviously, I cannot log a power outage, but a UPS generated forced shutdown due to low battery would also NOT be recorded)
Thanks, Don
|
|
|
|
|
Maybe you can try loging in the finalizer of your service (~MyServicename()) - this assumes of course that the finalizers of objects are called due to system shutdown. As you saw the Stop is not called the process is just closed.
|
|
|
|
|
Hello,
I can't figure this one out, so I'll be happy if someone lends me a helping hand here.
How do I instantiate an object with a generic type parameter if I don't know what the type parameter will be at run time?
Example:
namespace GenericTypeInitialization
{
class Program
{
static void Main()
{
Console.WriteLine("Press 1 for FooA, press 2 for FooB:");
ConsoleKeyInfo key = Console.ReadKey(true);
Type TypeOfFoo;
if (key.KeyChar == '1')
{
Console.WriteLine("FooA selected.");
TypeOfFoo = typeof(FooA);
}
else if (key.KeyChar == '2')
{
Console.WriteLine("FooB selected.");
TypeOfFoo = typeof(FooB);
}
Bar<TypeOfFoo> MyInstanceOfBar = new Bar<TypeOfFoo>();
}
}
class FooA {}
class FooB {}
class Bar<TFoo> {}
}
Obviously, the above code doesn't compile. I'm getting an error of
The type or namespace name 'TypeOfFoo' could not be found (are you missing a using directive or an assembly reference?)
How do I get the type parameter at run time then? I've tried various things, but none worked. Also, you can't instantiate the Bar<> class before '////'.
Thanks a lot for any input,
Michal
|
|
|
|
|
You will have to use reflection I guess
|
|
|
|
|
You can't. Generics in .NET are evaluated during runtime creating special types, [^]
The best solution to your problem is to use inheritance and base classes.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
Generics are designed to be used when you know the type at compile-time (early binding). When you don't know the type until run-time (late binding), you have to use reflection.
-----
You seem eager to impose your preference of preventing others from imposing their preferences on others. -- Red Stateler, Master of Circular Reasoning and other fallacies
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
Ok, so how would you use reflection to make the above example work as intended?
Thanks,
Michal
|
|
|
|
|
I reexamined your example, and her is what I suggest. Since you only have 2 well-known concrete classes, you may not need reflection for now, but generics is not the way to go either.
Make an interface:
public interface IFoo
{
void MyMethod();
}
Then have some implementation, 2 in you example:
public class FooA : IFoo
{
public void MyMethod() { Console.WriteLine("Hello from FooA"); }
}
public class FooB : IFoo
{
public void MyMethod() { Console.WriteLine("Hello from FooB"); }
}
Then, using your example code:
class Program
{
static void Main()
{
Console.WriteLine("Press 1 for FooA, press 2 for FooB:");
ConsoleKeyInfo key = Console.ReadKey(true);
IFoo myFoo = null;
if (key.KeyChar == '1')
{
myFoo = new FooA();
}
else if (key.KeyChar == '2')
{
myFoo = new FooB();
}
else
{
throw new InvalidOperationException("Wrong selection, you must select 1 or 2");
}
myFoo.MyMethod();
}
}
This example is pretty simplistic, but you get the idea. In this particular case, you didn't need generics nor reflection. In real-life application, this is rarely sufficient. Read on reflection, I am sure there are quite good articles on this site.
Good luck.
-----
You seem eager to impose your preference of preventing others from imposing their preferences on others. -- Red Stateler, Master of Circular Reasoning and other fallacies
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
Hello,
thanks for your reply. Unfortunately, this is not what I need.
Interface was my first thought on how to solve this, but I can't use the interface because I have to be able to copy the containing type by value, not by reference. If you declare the object as an interface, you can only copy it as a reference later on (unless you unbox it in which case you - again - need to know its type
I did not include the error handling in my example as I guess we are solving something else here.
Also, as I said, the type should not be instantiated before '////' mark. It's actually being instantiated much later on in the code, but I need to know the type first.
I've been working with reflection and generics before. My above example is a much simplified illustration of what I need to do, but the main issue is still finding out the type and passing it along as a parameter.
Thanks,
Michal
|
|
|
|
|
class Program
{
static void Main(string[] args)
{
Console.WriteLine((new Bar<FooA>()).ToString());
Console.WriteLine((new Bar<FooB>()).ToString());
}
}
public abstract class BaseFoo
{
}
public class FooA: BaseFoo
{
public FooA()
{
}
public override string ToString()
{
return "FooA";
}
}
public class FooB: BaseFoo
{
public FooB()
{
}
public override string ToString()
{
return "FooB";
}
}
public class Bar<TFoo> where TFoo : BaseFoo, new()
{
TFoo tFoo = new TFoo();
public override string ToString()
{
return tFoo.ToString();
}
}
|
|
|
|
|
Thanks for your post, but it doesn't solve the problem of instantiating the class with a generic parameter on demand during run time.
Also, the generic object can't inherit the abstract class because as I said, it has to be copiable by value, not by reference.
Michal
|
|
|
|
|
You'll be looking at TypeBuilder.MakeGenericType unfortunately I think...
|
|
|
|
|
Hello, Mark,
thanks, I've looked into TypeBuilder, but this class is used to build the objects on the fly. I don't need to BUILD the obect on the fly, I already have the objects well defined beforehand. I just need a reference for that object type.
So it looks like this cannot be accomplished in C#.
|
|
|
|
|
You could have an IDictionary<type,type> and preinitialize it with {typeof(Foo), typeof(Bar< Foo >)}, {typeof(Deh), typeof(Bar< Deh >)...}
modified on Thursday, February 07, 2008 6:13:04 AM
|
|
|
|
|
Hi,
Thank for your response.Let me explain it a bit further
Say i have a server process which listens for some changes in database.
When a change occurs i want to refresh my page in browser by notyfinig it.
I do not want to refresh my page i.e. every 5 seconds, i just want to refresh it ONLY on server change just like desktop applications do.
The problem is that refreshing evry n seconds has to much impact on my web server. The refresh action should be taken only when something really happens that makes sense
Is it possible ?
|
|
|
|
|
kibromg wrote: Thank for your response.Let me explain it a bit further
What response? This is your first post in the thread.
kibromg wrote: I do not want to refresh my page i.e. every 5 seconds, i just want to refresh it ONLY on server change just like desktop applications do.
I don't think this is possible. Web applications aren't the same as desktop applications. You're going to have to poll the server periodically to refresh the page. A good compromise would be to employ caching in your ASP.NET pages so that your pages aren't being built from scratch every time you hit the server.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
trying to marshall over some data from an unmanaged dll, however i heard that the marshaller cannot marshall an array of structs, in a struct.
c++:
<br />
#pragma pack(1)<br />
typedef struct{<br />
unsigned short propCnt;<br />
PRO_PROPERTY prop[200]; <-- this sh*t here...<br />
} PRO_CHANGEDPROPERTY;<br />
#pragma pack()<br />
<br />
#pragma pack(1)<br />
typedef struct{<br />
long apiCode;<br />
PRO_DATA data;<br />
} PRO_PROPERTY;<br />
#pragma pack()<br />
c#:
<br />
[StructLayout(LayoutKind.Sequential, Pack = 1)]<br />
public unsafe struct ProChangedProperty<br />
{<br />
public UInt16 propCnt;<br />
[MarshalAs(UnmanagedType.Struct, SizeConst = 200)]<br />
public ProProperty[] prop;<br />
}<br />
[StructLayout(LayoutKind.Sequential, Pack = 1)]<br />
public struct ProProperty<br />
{<br />
public Int32 apiCode;<br />
public ProData data;<br />
}<br />
i cant seem to figure this one out, any help would be appreciated.
|
|
|
|
|
Hi All,
I have application to make and delete appointments.
Here is some code to make the appointments:
string myProp = "test";
Outlook.Application outlookApp = new Outlook.Application();
Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem (Outlook.OlItemType.olAppointmentItem);
oAppointment.Subject = "This is the subject for my appointment";
oAppointment.Body = "This is the body text for my appointment";
oAppointment.Location = "Bongerd 331";
oAppointment.Start = Convert.ToDateTime("31/01/2008 10:00:00 AM");
oAppointment.End = Convert.ToDateTime("31/01/2008 12:00:00 PM");
oAppointment.ReminderSet = true;
oAppointment.ReminderMinutesBeforeStart = 15;
oAppointment.UserProperties.Add(myProp, Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, true, System.Reflection.Missing.Value);
oAppointment.UserProperties[myProp].Value = "mijn";
oAppointment.Save();
and to delete :
String sCriteria;
string impNr = "mijn";
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("mapi");
Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.Items oItems = (Outlook.Items)oCalendar.Items;
sCriteria = "[test] = '" + impNr + "'";
Outlook.Items oRestrictedItems = oItems.Restrict(sCriteria);
oRestrictedItems.IncludeRecurrences = true;
Outlook.AppointmentItem oAppointment;
Outlook.AppointmentItem oAppt;
oAppt = (Outlook.AppointmentItem)oRestrictedItems.GetFirst();
oAppt = (Outlook.AppointmentItem)oRestrictedItems.GetNext();
sCriteria = "[test] = '" + impNr + "'";
oAppointment = (Outlook.AppointmentItem)oItems.Find(sCriteria);
if (oAppointment is Outlook.AppointmentItem)
{
oAppointment.Delete();
}
else
MessageBox.Show("No object found");
it works fine for one appointment, bud the problem is that for making the appointments i have to use a Foreach loop (depending on some situations)..so there wil be always made more then one appointments and they get all the same userproperty value...bud now wen i click on 'delete' it deletes only one of the maded appointments...how can i make a loop to delete all appointments with same userproperty value???? maybe some code?
thanx
|
|
|
|
|
I have three panels one fills the app and the other you can drag into it, but I want to nest them to stay in one column, how do I do that?
|
|
|
|
|
Is this the same question from yesterday?
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Can some one point me in the direction of some example code that allows you to use multiple text colors for the text on a tree node.
I can find examples where the text foreground/background can be overridden for the complete string, but none that show how multiple colors can be used in the same string.
Many thanks
RK
|
|
|
|
|
Hi,
I haven't done this myself (for treeviews that is) but you will need to set the DrawMode
to TreeViewDrawMode.OwnerDrawText and provide a drawing handler. Google/MSDN will provide
the details, and I trust CodeProject holds articles using it too.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
How to make form as a model Window???
Thankxxxxxxxx In Advance!!!!!!!!!
Truth Is The Simplest !!!!
|
|
|
|
|
Do you mean modal? Use .Show() or .ShowDialog() depending on your needs.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|