|
I use a System.Timers.Timer for my Windows Services too.
The Timer should be a field of the class, the OnStart method should Enable or Start the Timer and complete.
|
|
|
|
|
Hi Guys
Can anybody help me to read the csv file using c# and store in the sql database.
Subash
|
|
|
|
|
If you look down this page you'll see you're the 3rd person to ask a similar question in the last few hours. Perhaps you can get some ideas from what they've posted and the relevant replies.
Could it be that you're all doing the same homework assignment?
|
|
|
|
|
What if all of the names belong to the same person?
|
|
|
|
|
That's exactly what I was starting to think but the "member since" is different for all of them.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Definitely not me
I was just looking for a good practice to do it, and yes, I've mocked csv questions once before for their frequency
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
..or they could just ask each other - they're probably all in the same classroom
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Try reading this one
clickety[^]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
Need some help regarding unsafe code.
Am trying to get create an array of pointer to a struct, and not getting through with it.
here is a sampe code
public struct RoomDef
{
public ushort Id;
public string Name;
public string Status;
public string Location;
}
Within a function i have coded the following.
RoomDef* []nee = new RoomDef();
unsafe
{
testPtr = new RoomDef();
nee[1] = & testPtr;
}
This is just a snippet of the code and there are no Syntax errors anywhere. But while I compile it gives me an error stating "Cannot take the address of, get the size of, or declare a pointer to a managed type"
Have tried using the Fixed statement as well, still no go.
I can get the address of the individual members of the structure. But not the structure itself.
Any help will be appreciated.
modified on Wednesday, September 17, 2008 8:51 AM
|
|
|
|
|
First the length of the nee array is only one, so nee[1] goes past the end. Second, testPtr is the managed type. It's already a pointer so you don't need to take the address of it.
Try: nee [1] = testPtr;
|
|
|
|
|
Thanks for the Reply,
I have handled the array part. But no, nee [1] = testPtr; does not work.
|
|
|
|
|
Alan Balkany wrote: testPtr is the managed type. It's already a pointer so you don't need to take the address of it.
No, as it's a value type, testPtr isn't a pointer at all.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I think you can have a pointer to a value type. When you make a struct with 'new' I think it's allocated in the heap. I think structs are only put on the stack when they're local variables.
|
|
|
|
|
See any work around for it?
|
|
|
|
|
I'm still looking at it. I suspect a class instead of a struct would work, but I still think a struct should work. Give me a few minutes...
|
|
|
|
|
I have tried using a class , no luck
|
|
|
|
|
This works:
public struct RoomDef
{
public ushort Id;
public string Name;
public string Status;
public string Location;
};
private void Form1_Load(object sender, EventArgs e)
{
RoomDef []nee = new RoomDef[5];
RoomDef testPtr = new RoomDef();
nee[1] = testPtr;
}
The 'struct' can be replaced with 'class' and it still works.
I suspect the array of structs is five 14-byte structures that follow each other in memory. But if a class is used, I suspect the array is five 4-byte pointers to RoomDef objects allocated in the heap.
It's hard to test this theory because using the sizeof() operator generates a compile error.
|
|
|
|
|
Thanks Alan,
But then, the code above declares an array of structures rather than an array of pointers isnt it? Correct me if am wrong, please.
|
|
|
|
|
If you substitute 'class' for 'struct' it will be an array of pointers. Classes are implemented as pointers to the data in the heap.
|
|
|
|
|
Alan Balkany wrote: I suspect the array of structs is five 14-byte structures that follow each other in memory.
Actually it's five 16-byte structures that follow each other in memory. The members in the struct are padded to the next word boundary, so there is two unused bytes after the ushort.
Alan Balkany wrote: But if a class is used, I suspect the array is five 4-byte pointers to RoomDef objects allocated in the heap.
The array is five references (4 or 8 bytes depending on the platform), however no RoomDef objects are created to populate the array when the array is created. All the references are null from start.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for the clarifications, Guffa.
|
|
|
|
|
I noticed an interesting quirk in C#: You can only use the sizeof() operator on a struct if it only contains value types. Replacing the three string members in RoomDef with ushort allows sizeof() to be used on the struct.
|
|
|
|
|
Alan Balkany wrote: I think you can have a pointer to a value type.
Yes, you can, but the variable we are talking about is not a pointer.
Alan Balkany wrote: When you make a struct with 'new' I think it's allocated in the heap.
No, it's not. The constructor only creates the value, it's not allocated anywhere. In this case the value is then assigned to the local variable.
Alan Balkany wrote: I think structs are only put on the stack when they're local variables.
It is a local variable.
Besides, a struct is never allocated on the heap by itself. A struct can be a part of a class that is allocated on the heap, it can be part of an array that is allocated on the heap, or it can be boxed inside an object that is allocated on the heap, but never on it's own.
Despite everything, the person most likely to be fooling you next is yourself.
modified on Wednesday, September 17, 2008 2:55 PM
|
|
|
|
|
You should use a class instead of a structure, so that you can allocate instances of it that will survive the local scope.
If you would have succeeded in putting the pointer in the array, it would be a pointer to the structure allocated in the stack frame of the method. When you return from the method, the structure doesn't exist any more, so the pointer is no longer valid.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for the Reply,
Will c heck as a class, but then any idea why it gives me an compile error when i do it this way?
|
|
|
|