|
Hi Guys,
Many thanks for all your inputs. Very valuable to a Windows newbie!
What I think I will do is run a thread with normal priority that tests the stopwatch elapsed ticks value and do my 10ms tasks when it trips over frequency / 100 to give me ticks per 10ms.
I have set the code to relinquish the cpu if the stopwatch tick count hasn't incremented sufficiently this cpu time slice. I am assuming the time slices are about every ms.
Here is the code. Any comments or anything I am doing wrong?
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;
namespace WFSO
{
class Program
{
static void Main()
{
Thread t = new Thread(Tick);
t.Start();
Console.ReadLine();
t.Abort();
Console.ReadLine();
}
static void Tick()
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
long tickcount = Stopwatch.Frequency / 100;
while (true)
{
if (stopWatch.ElapsedTicks > tickcount)
{
stopWatch.Reset();
stopWatch.Start();
}
Thread.Sleep(0);
}
}
}
}
Thank you once again. Bruce
|
|
|
|
|
Hi Bruce,
Bruce Coward wrote: I am assuming the time slices are about every ms.
Where do you get that idea? The scheduler runs based on the system clock, that is around 16 msec on modern hardware (it used to be 55 msec on Pentium 3 running Win95), and it corresponds to the base frequency of regular timers, see my timers article.
It could be better on PDAs running WinCE, I don't know (and don't expect it to be).
Hence, your code will approximately run at 16 msec intervals, each Thread.Sleep(0) will make it wait for the next tick; the StopWatch is not going to do anything useful in that code.
BTW: why aren't you using a multimedia timer (assuming it exists on WinCE)?
Luc Pattyn [Forum Guidelines] [My Articles]
- 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 the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:04 AM
|
|
|
|
|
"Time slice every 1ms"
I think I read that in the embedded training but I am now checking again.
Many thanks, Bruce
|
|
|
|
|
I have a custom control in C# and one of the properties is an internal class that consists of a list of another class. The control and the class work fine, except that every time I touch a form on which the control exists, it adds extraneous lines to the designer code.
Here's the property in the control. The DefaultValue is null, so my assumption is that it should not create anything in the designer code:
private PopupTable gridColumns = null;
[Category("Appearance"), Description("Collection of Columns to show in grid"),
DesignerSerializationVisibility( DesignerSerializationVisibility.Visible), DefaultValue(null)]
public PopupTable GridColumns
{
get { return gridColumns; }
set
{
if (value != null) gridColumns = value;
}
}
Here's what it inserts into the designer code in a VB form:
New fctgControls2.PopupTable.Add(PopupColumn1)
New fctgControls2.PopupTable.Add(PopupColumn2)
New fctgControls2.PopupTable.Add(PopupColumn3)
New fctgControls2.PopupTable.Add(PopupColumn4)
So, every time I touch a form, I have to go in and remove this junk from the designer code. After that, the app works fine.
Any ideas?
|
|
|
|
|
This normally happens by being set in a default constructor. Have you checked there?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
The default constructor creates a new list. So you're saying if I move that code to another method and leave the default constructor blank, that should take care of it?
I'll try that.
|
|
|
|
|
It wasn't quite that straightforward, but that was essentially the problem. Some of the controls were inherited from that base control and there was code in the OnLoad event to initialize the collection. I surrounded that code with
if (!DesignMode)
{
}
That took care of it. Thanks for your help.
|
|
|
|
|
No problem
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I want to add a windows media player component but the file cannot be loaded.What can I do? Please help me!
I need your suggestions.
Thanks in advance.
|
|
|
|
|
The problem is solved. Thanks for your help.
|
|
|
|
|
Hi, i'm trying from my application, get the handle of a datagrid into another. But it isn't works....!!! I got a handle and when i got the class name, it returned "WindowsForms10.SCROLLBAR.app.0.378734a"... and it isn't like datagrid classname. Please, can you help me?.
Thanks.
|
|
|
|
|
This seems, to me, to be a rather odd thing to do.
Perhaps if you give a more complete description of what it is you want to achieve, with perhaps a small bit of code, you might get more response.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks for you reply.
Sure. I will tell you the complete matter...
I'm working with CCF 2008, then i have an hosted application and this launch any actions at double click on a specific datagrid. I build a global hook to trap double-click event on datagrid and get the row (by the handle). But on debug, the returned handle not corresponding to datagrid even a SCROLLBAR. i don't understand. It works fine at another controls, on textbox, on forms, but not on datagrid.
There is the code line;
private void MouseHook1_MouseDoubleClick1(object sender, System.Windows.Forms.MouseEventArgs e)
{
StringBuilder build = new StringBuilder(256);
OpenWindowGetter.GetWindowText((IntPtr)sender, build, 256);
List<string> strHijos = OpenWindowGetter.GetChildWindows((IntPtr)sender);
....
}
And ever, this return SCROLLBAR in generic list.
Please, tell me if you want to view more code.
Oh. Sorry for my english. I'm not too expierenced with it.
|
|
|
|
|
Member 3324037 wrote: Oh. Sorry for my english. I'm not too expierenced with it
Do not apologize for your English, it is fine.
If it is the case that you are expecting strHijos to be filled with the handles for the cells of the datagrid , I believe you are destined for disappointment. GetChildWindows is returning the only child window of the grid, its scrollbar , since this is the only thing that has a handle.
I believe, although I could be wrong, that the grid controls do not create a window for each cell, they just draw a cell-shaped representation at the place where each cell should be.
For your future reference, if your first message had been like this one I'm sure that you would have had a more helpful reply than I am able to give here. Also, although I don't think it makes a difference in this case, you should make it clear if you are using a DataGrid or a DataGridView .
Hopefully, someone will be able to come up with an idea to help you.
Good luck!.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks again.
That's right. It's the only handle returned by DataGrid (not gridview, not DataGridView). By other hand, when i clicked (single-click) on cell to edit, the hook that trap mouse-click event, i got another handle, i find it by another application (to get windows and controls list) and it return that it handle correspond to "EDIT" class name it means that exist a handle for each textbox, listview, or any control into datagrid?
Thanks to Henry for give me a clue, and if anybody can help me, thanks in advance too..
|
|
|
|
|
Is this possible: I have a form with a datagridview. I have an event handler for the grid's CellEnter event but this event is fired before the form's load event. I have a break point at the form's load event and one at CellEnter but the CellEnter is handled before the form's load event.
Also, does anyone know the tool (I think it comes with VS2005) which shows all events as they occur?
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
|
you may use a Flag to control the flow.
Calin
|
|
|
|
|
I understand when it occurs, but shouldn't the form's load event occur prior to all the children's events? DataGridView is a child of the form.
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
As I add items to a ListView, can I also set a background colour fo the row just added based upon the value of an item in the row please?
|
|
|
|
|
ListView.Items[0].BackColor = Color.Red;//or what ever color you want
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
Hi,
How can i collect icons of each file type from system? I went through some examples but they all requires Full Path of file but all I've is Extension of file.
Thanks in advance
|
|
|
|
|
This[^] article might help.
Calin
|
|
|
|
|
Hi,
Any idea how to make a Calendar Column in a dataGridView control?? You know, the one that let's you pick from a drop down calendar.
Please help.
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|